I have a variable statenameabr (state name abbreviation) which I changed from string to numeric. In the prior post, it was recommend to use the -inlist- command. I thought I would use that as well since the -inlist- command can 2 and 255 arguments for reals but limited for string var.
I suggested the following and not sure if that would work.
Code:
encode statenameabr, gen (statenameabr1)
Code:
gen statemedicaid = 1 if inlist (statenameabr1, "AL", "AS", "AZ", "CA",....)
My end goal is:
1. I can look at the distribution of education, income, insurance status of people in states that have expanded medicaid compare to those that did not. I am thinking once I create the statemcaidexp variable i should be able to do that.
2. Of the states in each group a further stratification of those to create a control and treatment group within each of the groups created in #1.
Here are some of the variables I have in my data set. For goal #2, I would use the variable -ever_had_fqhc- and -wanted-
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input byte year float(n_county wanted ever_had_fqhc) str2 statenameabr 15 1 1 1 "AL" 18 1 1 1 "AL" 17 1 1 1 "AL" 16 1 1 1 "AL" 8 1 1 1 "AL" 13 1 1 1 "AL" 6 1 1 1 "AL" 14 1 1 1 "AL" 12 1 1 1 "AL" 10 1 1 1 "AL" 4 1 1 1 "AL" 11 1 1 1 "AL" 17 2 1 1 "AL" 18 2 1 1 "AL" 16 2 1 1 "AL" 15 2 1 1 "AL" 6 2 1 1 "AL" 12 2 1 1 "AL" 4 2 1 1 "AL" 11 2 1 1 "AL" 14 2 1 1 "AL" 8 2 1 1 "AL" 10 2 1 1 "AL" 13 2 1 1 "AL" 17 3 1 1 "AL" 15 3 1 1 "AL" 18 3 1 1 "AL" 16 3 1 1 "AL" 13 3 1 1 "AL" 8 3 1 1 "AL" 6 3 1 1 "AL" 14 3 1 1 "AL" 11 3 1 1 "AL" 12 3 1 1 "AL" 10 3 1 1 "AL" 4 3 1 1 "AL" 17 4 1 1 "AL" 18 4 1 1 "AL" 15 4 1 1 "AL" 16 4 1 1 "AL" 4 4 1 1 "AL" 8 4 1 1 "AL" 14 4 1 1 "AL" 6 4 1 1 "AL" 10 4 1 1 "AL" 12 4 1 1 "AL" 13 4 1 1 "AL" 11 4 1 1 "AL" 18 5 1 1 "AL" 17 5 1 1 "AL" 15 5 1 1 "AL" 16 5 1 1 "AL" 10 5 1 1 "AL" 12 5 1 1 "AL" 13 5 1 1 "AL" 4 5 1 1 "AL" 11 5 1 1 "AL" 14 5 1 1 "AL" 6 5 1 1 "AL" 8 5 1 1 "AL" 15 6 1 1 "AL" 17 6 1 1 "AL" 16 6 1 1 "AL" 18 6 1 1 "AL" 13 6 1 1 "AL" 6 6 1 1 "AL" 8 6 1 1 "AL" 14 6 1 1 "AL" 11 6 1 1 "AL" 10 6 1 1 "AL" 4 6 1 1 "AL" 12 6 1 1 "AL" 17 7 1 1 "AL" 16 7 1 1 "AL" 18 7 1 1 "AL" 15 7 1 1 "AL" 12 7 1 1 "AL" 14 7 1 1 "AL" 13 7 1 1 "AL" 10 7 1 1 "AL" 8 7 1 1 "AL" 4 7 1 1 "AL" 6 7 1 1 "AL" 11 7 1 1 "AL" 17 8 1 1 "AL" 18 8 1 1 "AL" 15 8 1 1 "AL" 16 8 1 1 "AL" 8 8 1 1 "AL" 11 8 1 1 "AL" 14 8 1 1 "AL" 12 8 1 1 "AL" 13 8 1 1 "AL" 6 8 1 1 "AL" 10 8 1 1 "AL" 4 8 1 1 "AL" 15 9 1 1 "AL" 16 9 1 1 "AL" 17 9 1 1 "AL" 18 9 1 1 "AL" end label values n_county n_county label def n_county 1 "Alabama Autauga", modify label def n_county 2 "Alabama Baldwin", modify label def n_county 3 "Alabama Barbour", modify label def n_county 4 "Alabama Bibb", modify label def n_county 5 "Alabama Blount", modify label def n_county 6 "Alabama Bullock", modify label def n_county 7 "Alabama Butler", modify label def n_county 8 "Alabama Calhoun", modify label def n_county 9 "Alabama Chambers", modify label var year "Reshaped Year variable panel data" label var n_county "group(statename countyname)" label var wanted "1 if n_county started out with 0 FQHCs and then got 1 at some point in time and " label var ever_had_fqhc "1= for all obs of any n_county that has had 1 or more FQHC's at any point in tim" label var statenameabr "State Name Abbreviation"
0 Response to Grouping values within a variable?
Post a Comment