Hi!
I'm working building an anual dataframe, as the result of appending the respective monthly dataframe. At first, I build the first year with its respectiva variables and then I generate a loop for the next ones.
When I am generating the age variable it returns me an error because the td() command doesn't recognize the variable `anio' in that loop.
Here is an example of how I build it up without the loop:
g edad_012021=int((td(01jan2021)-fecha_nac)/365)
And there is the way I am coding into the loop (without other steps to prepare the dataframe):
forvalues anio=2012(1)2020 {
use "$datoscotiz\\`anio'_1_universo.dta", clear
g anio=`anio'
g mescargo=1
forvalues mescargo=2(1)12 {
append using "$datoscotiz\\`anio'_`mescargo'_universo.dta"
replace anio=`anio' if anio==.
replace mescargo=`mescargo' if mes==.
}
g edad_01`anio'=int((td(01jan`anio')-fecha_nac)/365)
}
I don't know if there is a problem with my code or maybe I should use another command.
Wish u can help me!
Thank's a lot for u all!
I'm working building an anual dataframe, as the result of appending the respective monthly dataframe. At first, I build the first year with its respectiva variables and then I generate a loop for the next ones.
When I am generating the age variable it returns me an error because the td() command doesn't recognize the variable `anio' in that loop.
Here is an example of how I build it up without the loop:
g edad_012021=int((td(01jan2021)-fecha_nac)/365)
And there is the way I am coding into the loop (without other steps to prepare the dataframe):
forvalues anio=2012(1)2020 {
use "$datoscotiz\\`anio'_1_universo.dta", clear
g anio=`anio'
g mescargo=1
forvalues mescargo=2(1)12 {
append using "$datoscotiz\\`anio'_`mescargo'_universo.dta"
replace anio=`anio' if anio==.
replace mescargo=`mescargo' if mes==.
}
g edad_01`anio'=int((td(01jan`anio')-fecha_nac)/365)
}
I don't know if there is a problem with my code or maybe I should use another command.
Wish u can help me!
Thank's a lot for u all!

Comment