Elementary question form a PhD student here...
I'm working on creating a variable derived with logic from 4 other variables with this code which follows a flowchart for this instrument which should ultimately be a 1 or 0:
generate CAMICU = 1 if cam_f1 == 1 & cam_f2_numeric >= 8 & ( cam_f3_numeric != 0 | cam_f4_numeric >= 4 )
How can I get 'CAMICU' to equal 0 if the above criteria are not met? I've tried the below using 'else'
. generate CAMICU = 1 if cam_f1 == 1 & cam_f2_numeric >= 8 & ( cam_f3_numeric != 0 | cam_f4_numeric >= 4 ), else CAMICU = 0
. generate CAMICU = 1 if cam_f1 == 1 & cam_f2_numeric >= 8 & ( cam_f3_numeric != 0 | cam_f4_numeric >= 4 ), else {if CAMICU != 1, CAMICU = 1}
. generate CAMICU = 1 if {cam_f1 == 1 & cam_f2_numeric >= 8 & ( cam_f3_numeric != 0 | cam_f4_numeric >= 4 )} else CAMICU = 0
. generate CAMICU = 1 if (cam_f1 == 1 & cam_f2_numeric >= 8 & ( cam_f3_numeric != 0 | cam_f4_numeric >= 4 )) else CAMICU = 0
. generate CAMICU = 1 if {cam_f1 == 1 & cam_f2_numeric >= 8 & ( cam_f3_numeric != 0 | cam_f4_numeric >= 4 )} else CAMICU == 0
. generate CAMICU = 1 if {cam_f1 == 1 & cam_f2_numeric >= 8 & ( cam_f3_numeric != 0 | cam_f4_numeric >= 4 )} else = 0
. generate CAMICU = 1 if cam_f1 == 1 & cam_f2_numeric >= 8 & ( cam_f3_numeric != 0 | cam_f4_nu
> meric >= 4 )
(805 missing values generated)
. else {
. CAMICU = 0 if cam_f1 != 1 | cam_f2_numeric < 8 | ( cam_f3_numeric = 0 | cam_f4_numeric < 4 )
command CAMICU is unrecognized
r(199);
. }
I'm using Stata/IC 14.2 on Windows. Thanks to everyone who got this far and is considering a reply!
Tom
I'm working on creating a variable derived with logic from 4 other variables with this code which follows a flowchart for this instrument which should ultimately be a 1 or 0:
generate CAMICU = 1 if cam_f1 == 1 & cam_f2_numeric >= 8 & ( cam_f3_numeric != 0 | cam_f4_numeric >= 4 )
How can I get 'CAMICU' to equal 0 if the above criteria are not met? I've tried the below using 'else'
. generate CAMICU = 1 if cam_f1 == 1 & cam_f2_numeric >= 8 & ( cam_f3_numeric != 0 | cam_f4_numeric >= 4 ), else CAMICU = 0
. generate CAMICU = 1 if cam_f1 == 1 & cam_f2_numeric >= 8 & ( cam_f3_numeric != 0 | cam_f4_numeric >= 4 ), else {if CAMICU != 1, CAMICU = 1}
. generate CAMICU = 1 if {cam_f1 == 1 & cam_f2_numeric >= 8 & ( cam_f3_numeric != 0 | cam_f4_numeric >= 4 )} else CAMICU = 0
. generate CAMICU = 1 if (cam_f1 == 1 & cam_f2_numeric >= 8 & ( cam_f3_numeric != 0 | cam_f4_numeric >= 4 )) else CAMICU = 0
. generate CAMICU = 1 if {cam_f1 == 1 & cam_f2_numeric >= 8 & ( cam_f3_numeric != 0 | cam_f4_numeric >= 4 )} else CAMICU == 0
. generate CAMICU = 1 if {cam_f1 == 1 & cam_f2_numeric >= 8 & ( cam_f3_numeric != 0 | cam_f4_numeric >= 4 )} else = 0
. generate CAMICU = 1 if cam_f1 == 1 & cam_f2_numeric >= 8 & ( cam_f3_numeric != 0 | cam_f4_nu
> meric >= 4 )
(805 missing values generated)
. else {
. CAMICU = 0 if cam_f1 != 1 | cam_f2_numeric < 8 | ( cam_f3_numeric = 0 | cam_f4_numeric < 4 )
command CAMICU is unrecognized
r(199);
. }
I'm using Stata/IC 14.2 on Windows. Thanks to everyone who got this far and is considering a reply!
Tom

Comment