Hi everyone, I hope you are doing well.
I'm posting here because I have a doubt regarding a loop I'm coding on Stata. I'm trying to create the same variable for 547 cities in three years, the point is that when I put the conditional of filling with missings if we are not working on the code of the city (in order) the rest of the cities just get missing and I don't get a interactive process as I expect to. In order to clarify what I'm trying let me show you the code that I have:
sort id_mpio year
foreach n of numlist 1/547 {
foreach var of varlist ineqdeco_vr_salario_`n'_2010 ineqdeco_vr_salario_`n'_2013 ineqdeco_vr_salario_`n'_2016 ///
ineqdec0_vr_salario_`n'_2010 ineqdec0_vr_salario_`n'_2013 ineqdec0_vr_salario_`n'_2016 {
preserve
replace `var' = . if id_mpio != `n'
}
egen gini_vr_salario_`n' = rowtotal (ineqdeco_vr_salario_`n'_2010 ineqdeco_vr_salario_`n'_2013 ineqdeco_vr_salario_`n'_2016)
replace gini_vr_salario_`n' = . if id_mpio != `n'
egen gini0_vr_salario_`n' = rowtotal (ineqdec0_vr_salario_`n'_2010 ineqdec0_vr_salario_`n'_2013 ineqdec0_vr_salario_`n'_2016)
replace gini0_vr_salario_`n' = . if id_mpio != `n'
drop ineqdeco_vr_salario_`n' ineqdeco_vr_salario_`n'_2010 ineqdeco_vr_salario_`n'_2013 ineqdeco_vr_salario_`n'_2016 ///
ineqdec0_vr_salario_`n' ineqdec0_vr_salario_`n'_2010 ineqdec0_vr_salario_`n'_2013 ineqdec0_vr_salario_`n'_2016
restore
}
Can someone tell me the mistake that I have on that code? Please!
Thanks!
Related Posts with How to reset a loop with a continues set of codes?
Count and recordHi all, My data has four variables: acty, deady, nation, and id. "acty" is the year when company is…
Creating variables for husband and wife using data for respondent and their partnerDear Statalist. I would like help to generate a variable, say level of education "educ" for the mal…
Choose Which Fixed Effect Has Coefficient 0Hi Statalisters, I'm running a fixed-effects regression with fixed-effects by region (e.g. Americas…
Threshold for small/large T in quarterly panel dataDear all, Sorry for basic question. I am estimating dynamic panel data model for 40 countries &…
Creating a variable equal to 1 if a name (i.e., string) at time t-4 appears at time tI have Brazilian electoral data with the names of candidates who ran for mayor from 2000 to 2016. Th…
Subscribe to:
Post Comments (Atom)
0 Response to How to reset a loop with a continues set of codes?
Post a Comment