-2

I want to generate 3 NEW variables using these variables in my data set:

  1. Ucod
  2. 19 variables in series by this name: Record_2, Record_3......Record_20

Both of them have values in alphanumerical format in it, basically ICD codes i.e, I150 I want to generate 3 new variables satisfying each of three new condition:

  1. People dying primarily of COVID (Var1=1 if Ucod= U07.1)
  2. People dying of a non-COVID condition WITH covid (Var2=1 IF Ucod != U07.1 & Record_2/20= U07.1)
  3. People dying of a non-COVID condition WITHOUT covid (Var3=1 if Ucod != U07.1 & Record_2/20 != U07.1)

Can anyone suggest a code which can help me to generate these 3 variables using these 3 condition.

Pkbti
  • 9
  • 3
  • This is difficult to answer until you explain clearly (1) which variables are numeric with value labels and which string ("alphanumerical format" has no Stata meaning otherwise) (2) whether `Record_2/20 != U07.1` means any of them or all of them, as the meaning of the notation is yours alone. – Nick Cox Nov 24 '22 at 21:04
  • @NickCox. (1), All the above mentioned variables are string (2) "Record_2/20 != U07.1" means all of them should NOT have U07.1. Thank you for helping me to understand this platform better, I have marked my all previous answers. Thanks – Pkbti Nov 25 '22 at 15:18
  • What does `Record_2/20= U07.1` mean: any of them? – Nick Cox Nov 25 '22 at 15:40
  • @NickCox Yes, any of them – Pkbti Nov 25 '22 at 15:48

1 Answers1

0

This may help. Note how I needed to define a toy dataset to give flavour to the problem.

* Example generated by -dataex-. 
clear
input str5(Ucod Record_2) str4(Record_3 Record_4)
"U07.1" "U000"  "U111" "U222"
"U999"  "U07.1" "U444" "U333"
"U888"  "U777"  "U666" "U555"
end

gen wanted1 = Ucod == "U07.1" 

gen count = 0 

quietly foreach v of var Record_* { 
   replace count = count + (`v' == "U07.1")
} 

gen wanted2 = Ucod != "U07.1" & count > 0 

gen wanted3 = Ucod != "U07.1" & count == 0 

list 

     +------------------------------------------------------------------------------+
     |  Ucod   Record_2   Record_3   Record_4   wanted1   count   wanted2   wanted3 |
     |------------------------------------------------------------------------------|
  1. | U07.1       U000       U111       U222         1       0         0         0 |
  2. |  U999      U07.1       U444       U333         0       1         1         0 |
  3. |  U888       U777       U666       U555         0       0         0         1 |
     +------------------------------------------------------------------------------+

Nick Cox
  • 35,529
  • 6
  • 31
  • 47