Hello there,
I have two variables, income of individuals from year 1968 to 2017 and their ages for the same years. I want to create a variable which indicates income for specific age. Like income of each individual at the age of 40. I wrote the following loop but it assigned 2017's income for all ages.

generate labory40=.

foreach x of varlist labory1968-labory2017{
foreach y of varlist age1968-age2017{
replace labory40=`x' if `y'==40
}
}

generate labory41=.

foreach x of varlist labory1968-labory2017{
foreach y of varlist age1968-age2017{
replace labory41=`x' if `y'==41
}
}
.
.
.

Any help is highly appreciated,