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
Store mean of many variables in a new fileHello, everyone! Suppose there are v1, v2, v3, t1, t2 five variables, now I want to calculate mean …
Tests for regression analysis (panel data)Hello, I'm analysing the effect of R&D expenditure on firm's ESG score and the moderating effec…
Select a certain number of variables from .dat fileHello everyone, I have a big .dat file that makes my laptop freeze every single time that I try to …
How can I extract the one particular strings from several strings?Hi all, I have some addresses separated by ";" in the following format: “ Univ London Imperial Col…
SEM - reporting results estimate store - esttabGood morning, how I can store and report results in sem? Usually, I work with estimates store [...] …
Subscribe to:
Post Comments (Atom)
0 Response to r(608) error in loop
Post a Comment