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
Issues with converting string to numerical or date in StataHi everyone, I am a new comer to Stata. Currently, I have issues with converting some imported dat…
Stata implementation of Conway's Game of LifeConway's Game of Life is a cellular automaton devised by John Conway in 1970, in which cells on an i…
Bootstrapping to obtain confidence intervals around differences in failure functionsI have a longitudinal dataset with 2 matched cohorts (Cohort==1 & Cohort==0) in a ratio of 1:3 t…
How to generate a dependent variable in a second stage from point estimates on hundreds of occupation binary variablesDear StataList, I do the following first stage regression: regress logwage i.occupation age gen…
Difference in differences (DID) before and after an eventHi everyone, I'm new to stata. I was trying to do a diff-in-diff test for a list of firms before 200…
Subscribe to:
Post Comments (Atom)
0 Response to Generate a lead variable in a panel
Post a Comment