Dear all,
I have a variable 'bday' showing the birthday of the individual in the Stata date code. I have another variable inc'yyyy''mm' showing the income status of individuals in year 'yyyy' and month 'mm'. For example, the income status of december 2016 is inc201612 and the income status of february 2016 is inc20162.
When the 'inc' variable takes the value '1' I need the 'inc' variabel for the given month and year to take the value 2, if the individual in that given month and year is between 18 and 29 years old.
I try to this writing:
This works well for the first 11 months of 2014 but then return the error code:
...since my `g' always takes month `k' and adds 1, i.e., also in december. So I need to replace `g' with 1 whenever `g'==13 (or when `k'==12). How do I do this inside the forval-loop?
I have a variable 'bday' showing the birthday of the individual in the Stata date code. I have another variable inc'yyyy''mm' showing the income status of individuals in year 'yyyy' and month 'mm'. For example, the income status of december 2016 is inc201612 and the income status of february 2016 is inc20162.
When the 'inc' variable takes the value '1' I need the 'inc' variabel for the given month and year to take the value 2, if the individual in that given month and year is between 18 and 29 years old.
I try to this writing:
Code:
forval j = 2014/2021{ forval k = 1/12 { local l = `j' - 29 local h = `j'- 18 local g = `k' + 1 replace inc`j'`k' = 2 if mør`j'`k' == 1 /// & inrange(bday, td(1/`g'/`l', td(1/`k'/`h') } }
Code:
td(1/13/1985) invalid
Comment