Hi!
I'm trying to create groups in my data: for every year and district I create a group that includes everyone 2.5 years more or less than that person. To do this, I created a loop that takes every year district group and only keeps the observations I want and appends them. I run a code that works up to a certain point and suddenly stops working. Here is my code:
keep person_id year district
duplicates drop
preserve
keep if _n>=1
gen group=.
save "file_1.dta", replace
restore
local i=1
levelsof district, local(lev_1)
levelsof year, local(lev_2)
foreach l_1 of local lev_1{
foreach l_2 of local lev_2{
preserve
keep if abs(year-`l_2')<=3 & district==`l_1'
keep person_id
gen year=`l_2'
gen district=`l_1'
gen group=`i'
append using "file_1.dta"
save "file_1.dta", replace
restore
local i=`i'+1
}
}
Thanks for any help!
Miranda
Related Posts with r(608) error in loop
only the estimated coefficientHi, Which could be the reason that Stata does not show me only the estimated coefficient?: ------…
Number of rows and columns of subplots using xtlineHi, how can I define the number of rows/columns of subplots when using "xtline"? The options "rows(…
Stata : Rr mantel heanzelI have SMR results by lauching this command : strate maxexpo_ardbis, per(100000) smr(taux_esto) and …
help with local macrosDear all, I would like to create several boxplots at once and combine them. i found the code below a…
Ramsey testHi, Which is the command in Stata 12 for the Ramsey Test with data panel? Thanks! …
Subscribe to:
Post Comments (Atom)
0 Response to r(608) error in loop
Post a Comment