Hi. From the data below, I want to create individual datasets for each treated state, i.e. where treat=1. The code below gives me empty datasets for all states where statenum>1, and I haven't been able to correct this. Could someone please help me?
Also, is there anyway to do this without creating a numerical variable for state, so that the state name can appear in the name of the .dta file created.
Also, is there anyway to do this without creating a numerical variable for state, so that the state name can appear in the name of the .dta file created.
Code:
preserve keep if treat==1 *creating a numeric variable for states encode state, gen(statenum) forvalues X=1/15 { keep if statenum==`X' save "${outdir}\treat`X'.dta", replace } restore input str50 state byte treat "Arunachal Pradesh" 0 "Arunachal Pradesh" 0 "Arunachal Pradesh" 0 "Arunachal Pradesh" 0 "Arunachal Pradesh" 0 "Arunachal Pradesh" 0 "Arunachal Pradesh" 0 "Arunachal Pradesh" 1 "Arunachal Pradesh" 1 "Arunachal Pradesh" 1 "Arunachal Pradesh" 1 "Arunachal Pradesh" 1 "Arunachal Pradesh" 1 "Arunachal Pradesh" 1 "Arunachal Pradesh" 1 "Arunachal Pradesh" 1 "Arunachal Pradesh" 1 "Arunachal Pradesh" 1 "Arunachal Pradesh" 1 "Arunachal Pradesh" 1 "Arunachal Pradesh" 1 "Arunachal Pradesh" 1 "Arunachal Pradesh" 1 "Arunachal Pradesh" 1 "Arunachal Pradesh" 1 "Arunachal Pradesh" 1 "Arunachal Pradesh" 1 "Arunachal Pradesh" 1 "Arunachal Pradesh" 1 "Arunachal Pradesh" 1 "Arunachal Pradesh" 1 "Assam" 0 "Assam" 0 "Assam" 0 "Assam" 0 "Assam" 0 "Assam" 0 "Assam" 0
Comment