Hello! This is my first time asking a question on here, so please excuse me if it is phrased incorrectly, or difficult to understand.
I am working with a panel dataset that has 22 years of observations at the school district/Year level. School districts are identified using the variable "Code," and there is a time variable "Year." I also have a dummy, treatment variable, "Treat," that is 1 when a school district has a wind project within its boundaries, and 0 otherwise. The treatment variable changes from 0 to 1 in the first year that the wind project has come online. However, many districts do not have any wind projects, and thus Treat = 0 across all 22 years of observations. Additionally, wind projects came online at different times in different districts. For example, in district 1 a wind project came online in 2005, while in district 5 a project came online in 2017.
I need to create a new variable "firstYear" that is equal to the first year that a project came online, so for district 1 it would be 2005 and for district 5 it would be 2017, etc. I have tried to use the foreach command to execute this, but I am getting stuck. The code I have tried so far is:
gen firstYear = . *Create firstYear as all missing because I only need these values for districts with wind projects
foreach row of Treat {
replace firstYear = `row' Year if `row' Treat == 1
* Add a column for firstYear and
continue if `row' Treat == 0
}
This is returning a syntax error, which I believe is due to my inexperience with the foreach command, however I am also unsure if the logic I used is correct. I would appreciate help on both fixing the syntax and the logic (if there are other errors).
Additionally, if there is a better way to do this, please let me know!
Thank you!
Related Posts with Identify first time dummy variable = 1 across observations in a panel data set
Creating interaction terms between a group of year dummies and a group of product dummies and how to use them in a regression equation.Hello, I have a challenge with how to create a kind of interaction terms for purposes of running a …
What's the correct way of interpreting the (exponentiated) log odds?Hello everyone, I am trying to translate the following output to a table in a word document. Howev…
Importing several excel files: matching rowsHi everyone, I imported over 250 excel files and appended them all together to 1 dta file, by using…
Survey concordance correlationHello everyone: Is there any way to obtain accurate estimates and 95% confidence intervals for the …
Omitted independent variables in xtabond2 using twostep system GMMHi, I am trying my data set in two-step System GMM, three variables annual GDP growth rate, Bond mar…
Subscribe to:
Post Comments (Atom)
0 Response to Identify first time dummy variable = 1 across observations in a panel data set
Post a Comment