Hi,
I have the following dataset:
I want to create a loop to generate variables that show one year after the exit year, two years after the exit rate, and so on.
For example, if my exit=2013, I would want to create variables t1 that shows the income in 2014, t2 that shows income in 2015, and so on.
So far I have the following, but for some reason it does not work
I have the following dataset:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(ID exit income_2014 income_2015 income_2016) 1 2013 25000 27000 28000 2 2014 30000 32000 33000 3 2015 28000 29000 30000 4 2013 26000 28000 29000 end
For example, if my exit=2013, I would want to create variables t1 that shows the income in 2014, t2 that shows income in 2015, and so on.
So far I have the following, but for some reason it does not work
Code:
gen t1 = .
gen t2 = .
gen t3 = .
gen t4 = .
gen t5 = .
foreach t in 2003/2015 {
* Calculate the year after finding a job
local job_year_t1 = `t' + 1
local job_year_t2 = `t' + 2
local job_year_t3 = `t' + 3
local job_year_t4 = `t' + 4
local job_year_t5 = `t' + 5
* Populate income variables for each year after finding a job
replace t1= income_`job_year_t1' if exit == `t'
replace t2= income_`job_year_t2' if exit == `t'
replace t3= income_`job_year_t3' if exit == `t'
replace t4= income_`job_year_t4' if exit == `t'
replace t5= income_`job_year_t5' if exit == `t'
}

Comment