@pjones98 wrote:
I am using the HRS for a project and would like to create an 'insurance' variable pulling values from the individual insurance indicators that have overlap with each other.
I have medicaid (yes/no) as 'medicaid'
combine spouse (yes/no) or personal employe plan (yes/no) or any gov plan (yes/no) as 'other'
private insurance is a counted variable of how many plans they have, where I would like to do as >=1 means they have private insurance
i've tried doing
if medicaid=1 then insurance=1;
else if employee=1 or spouse=1 or gov=1 then insurance=2;
else if private>=1 then insurance=3;
else insurance=.;
but since people can have more than one type of insurance, none of the frequencies are correct after medicaid.
Is there a way to properly code this?
Is your intent that if they have the private insurance >= 1 regardless of the employee, spouse or gov values to set the resulting variable insurance to 3? If so then change the order of the if/then/else so the private is compared before the employee/spouse/gov variables.
But agree that example data and desired result is needed. The example only needs to include some identifier, for discussion of specific respondents, and the values of the variables to consider and what the result looks like.
This code will simulate, at least as I understand your data at this time, examples of pretty much all the types of cases that could exist of the various variables shown and the results of your code. You can tell us which values of ID are incorrect and why.
data have;
retain id;
do medicaid=.,0,1;
do employee=.,0,1;
do spouse =.,0,1;
do gov =.,0,1;
do private = .,0,1,2;
id+1;
if medicaid=1 then insurance=1;
else if employee=1 or spouse=1 or gov=1 then insurance=2;
else if private>=1 then insurance=3;
else insurance=.;
output;
end;
end;
end;
end;
end;
run;
If this is not like your data then you need to provide an example.