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
Interpreting Stata's R^2 and rho in a fixed effects regressionAs i understand it, the rho indicates the percentage of the variance that is due to individual fixed…
How replace text value of variable with numberSo I have a variable education that has lots of values in text specifying 'bachelor 1', 'bachelor 2'…
How to unzip multiple files into different folders (with different names)Hello everyone, I am new in this forum, and I hope you can help me solve this. What I have to do: -…
Dynamic Panel threshold modelI am writing a paper applying a dynamic panel threshold model. however, I am not sure if I apply cor…
Create a column from a different column and combine multiple datasetsI have 50 U.S. state daily max temperature datasets in the CSV form from 1990 to 2019. This is a pa…
Subscribe to:
Post Comments (Atom)
0 Response to Generate a lead variable in a panel
Post a Comment