Sunday, February 28, 2021

Function to give year of start

Dear all,

I have a dataset with the US census for the 1970-1999 period combined with a dataset with information about different public policies concerning the labor market. I have a cross-section of several million individuals, with a variable indicating the state of birth. I also have a series of dummy variables indicating if a policy was active at each of the available years. For example, if in Nevada the policy called G started in 1980 and was active for the rest of the period, for individuals born in Nevada, the dummy variables g_1970birth-g_1979birth will be 0, while the variables g_1980birth-g_1999birth will be 1.
I want to create a new variable, call it year_g, which will give me the year the policy G started in for the state of birth of each individual (year_g=1980 for the previous example). For that purpose, I have written the following line:

Code:
forval w=1970(1)1999{
replace year_g=`w' if g_`w'birth==1 & g_`w-1'birth==0
}
The idea is that since it requires the previous year to be 0, this can only work with the starting year. However, I'm obtaing year_g=1999 for all the observations, and I can't seem to figure out what is wrong with the code. I'd be very grateful if someone could help me figure it out.
Thank you very much for your time.


No comments:

Post a Comment