Hello All,
I am learning STATA and have not been able to find the answer to the following question online:
What syntax do I use in Stata to generate a variable that requires multiple conditions? Here is what I'm trying to use and it's not working:
bysort id visit_num: generate pre_hepb3_compliant = 1 if age_at_visit >= 176 & if age_at_visit < 570 & pre_hepb_3 ==“Y
replace pre_hepb3_compliant = 0 if age_at_visit >= 176 & if age_at_visit < 570 & pre_hepb_3 != “Y”
I am getting an error message that says: “Y” invalid name
I want to create a new variable (pre_hepb3_compliant)
I want it to equal 1 if
child's age is between 176 days and 570 days
AND
child has received the pre_hepb_3 vaccination
So there are three conditions for each participant before assigning a value, 1 or 0 to the new variable:
1. age at clinic visit is greater than or equal to 176 days old
2. age at clinic visit is less than 570 days old
3. vaccination dose received as indicated by an existing variable (pre_hepb_3 is equal to Y)
Only then do I want a 1 for the newvar, "pre_hepb3_compliant". Otherwise, I want the newvar "pre_hepb3_compliant" to equal 0.
Ideas please? I would like to create a whole series of variables that require multiple conditions and so your help will be very much appreciated.
Dayna Matthew
I am learning STATA and have not been able to find the answer to the following question online:
What syntax do I use in Stata to generate a variable that requires multiple conditions? Here is what I'm trying to use and it's not working:
bysort id visit_num: generate pre_hepb3_compliant = 1 if age_at_visit >= 176 & if age_at_visit < 570 & pre_hepb_3 ==“Y
replace pre_hepb3_compliant = 0 if age_at_visit >= 176 & if age_at_visit < 570 & pre_hepb_3 != “Y”
I am getting an error message that says: “Y” invalid name
I want to create a new variable (pre_hepb3_compliant)
I want it to equal 1 if
child's age is between 176 days and 570 days
AND
child has received the pre_hepb_3 vaccination
So there are three conditions for each participant before assigning a value, 1 or 0 to the new variable:
1. age at clinic visit is greater than or equal to 176 days old
2. age at clinic visit is less than 570 days old
3. vaccination dose received as indicated by an existing variable (pre_hepb_3 is equal to Y)
Only then do I want a 1 for the newvar, "pre_hepb3_compliant". Otherwise, I want the newvar "pre_hepb3_compliant" to equal 0.
Ideas please? I would like to create a whole series of variables that require multiple conditions and so your help will be very much appreciated.
Dayna Matthew
Comment