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
Effective Reproductive NumberHello! Is there a way to calculate Effective Reproductive Number (Rt) in STATA? Thank you very muc…
Tobit with vce(robust) or notHi, When I run tobit model specifying vce(robust), it does F test to test the hypothesis that the co…
Ordered Logit, Multinomial Logit- InterpretationsI am trying to run ordered logit for a dependent variable that takes values -1,0,1. Suppose educatio…
Non-normal distribution of latent variable in structural equations modelling - transformation?I have a simple path model with several latent variables that are ostensibly well enough indicated b…
Constrained optimization in StataDear Stata uses, I am having a constant optimization problem to solve in Stata I am having three var…
Subscribe to:
Post Comments (Atom)
0 Response to r(608) error in loop
Post a Comment