Cross-posted on stack overflow.
I need help in generating a lead variable in a panel. I want to generate a lead income variable (let's call it V1) by CMA, Province and Year such that the data looks like;
CMA Province Year Income V1 TO A 1990 $5 $8 TO A 1991 $8 . MT A 1990 $12 $7 MT A 1991 $7 . AB B 1990 $5 $15 AB B 1990 $15 . etc
I was using the following codes, but I was getting only missing values.
gsort CMA Province -Year Income gen ld_inc = Income[_n-1] if Year == Year[_n-1] + 1 replace ld_inc = ld_inc[_n-1] if Year == Year[_n-1] & missing(ld_inc)
Is there something wrong with my code and what I am getting wrong? Thanks in advance.
Related Posts with Generate a lead variable in a panel
Generating a variable reporting the difference between values of another variable considered in different years (Panel dataset)Hi everyone, I think my question is quite simple but I wasn't able to solve it. I have a panel data…
Regression with or without dummy variable? + visualizationHi all, 1. I need to perform a regression with the log of house price (loglprice) as a dependent va…
Interpretation of interaction variableDear all, I am analyzing whether a CEO turnover (c. 600 events) has a long-term (5 years) impact on…
Checks for Tobit regressionHi i have done a tobit regression to estimate the price elasticities of demand for alcohols and have…
outreg2 for ivreghdfeDear Statalists, I am quite new to reghdfe and ivreghdfe. I hope someone can help me with my code. …
Subscribe to:
Post Comments (Atom)
0 Response to Generate a lead variable in a panel
Post a Comment