Hello,
I'm a relatively new SAS user so I'm not sure how to do this but it seems like it should be possible.
I have variables for all 50 states and want to split them into a new variable depending on whether or not they have expanded Medicaid coverage or not. Then, I want to be able to make the Medicaid variable into a binary 0/1 in order to run a diff-in-diff model. Is that possible? In my head it would look something like:
ACAyes = (Arizona, Arkansas, California);
ACAno = (Alabama, Florida, Georgia);
Medicaid = 0;
if ACAyes = 1 then Medicaid = 1;
if ACAno = 1 then Medicaid = 0;
Thanks for your help!
So just to be clear, you have variables named Arizona, Arkansas, California and so on, correct? What do those variables contain?
Yes, I should have clarified that! I created each variable with a state name from an original variable, _STATE, which coded each state according to a number. So, now that you point that out, I should probably go back to the original variable to make the Medicaid variable. Perhaps something like:
Medicaid = 0;
if _STATE = (1, 2, 3) then Medicaid = 1;
if _STATE = (4, 5, 6) then Medicaid = 0;
Coding: if _STATE = (1, 2, 3) is wrong sas syntax. what you mean is:
if _STATE in (1 2 3) then Medicaid = 1; else Medicaid = 0;
assuming that (1 2 3) are the only those with Medicaid = 1;
Ah, thank you for pointing out my syntax. As far as the if/else statement, there are a few states and territories in the original _STATE variable that I don’t want to be in either grouping and want them to be disregarded for the diff-in-diff model. How would you suggest I code the statement so that the states I want to disregard don’t wind up in the model? Would it work to sssign them to another number?
As far as the if/else statement, there are a few states and territories in the original _STATE variable that I don’t want to be in either grouping and want them to be disregarded for the diff-in-diff model.
In your data step or PROC, if for example you don't want states 5 and 27 in the analysis, then
where state not in (5,27);
Thank you! Can I ask one more question? I have tried this code:
data newCOMBO where _STATE not in (2 22 23 49 51 66 72 78);
set COMBO;
Medicaid = 0;
if _STATE = (4 5 6 8 9 10 11 15 17 18 19 21 24 25 26 27 30 31 32 33 34 35 36 38 39 41 42 44 50 53 54) then Medicaid = 1;
run;
But keep running into these errors:
WARNING: The data set WORK.NEWCOMBO may be incomplete. When this step was stopped there were 0
observations and 160 variables.
WARNING: The data set WORK.WHERE may be incomplete. When this step was stopped there were 0
observations and 160 variables.
WARNING: Data set WORK.WHERE was not replaced because this step was stopped.
WARNING: The data set WORK._STATE may be incomplete. When this step was stopped there were 0
observations and 160 variables.
WARNING: Data set WORK._STATE was not replaced because this step was stopped.
WARNING: The data set WORK.NOT may be incomplete. When this step was stopped there were 0
observations and 160 variables.
WARNING: Data set WORK.NOT was not replaced because this step was stopped.
Everything works fine up until this point so I'm thinking this step is definitely written wrong.
if _STATE in (4 5 6 8 9 10 11 15 17 18 19 21 24 25 26 27
30 31 32 33 34 35 36 38 39 41 42 44 50 53 54) then Medicaid = 1;
Ack, thank you!!
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.