I am looking into weekly earnings data, where I have defined my data as pre-pandemic earning data and post-pandemic earning data. Now for some individuals, I have some missing values for the post-pandemic period which I want to replace with their pre-pandemic earnings. However, I am struggling with the coding for this panel data. I was hoping someone could help me with. Thanks in advance.
Asked
Active
Viewed 473 times
-1
-
The statistical rationale for this is puzzling. – Nick Cox Jun 08 '22 at 10:13
-
Please provide enough code so others can better understand or reproduce the problem. – Community Jun 08 '22 at 12:39
1 Answers
1
It is always easier if you share example data (see dataex
) or at least list what variables you have. The example below will therefore most likely need to be edited.
* Sort the data by individual id and the time unit
* that indicates if this the obs is pre or post pandemic
sort id time
* This replaces the earnings value with a missing value if the
* id var is the same as on the next row AND the earnings var
* on is missing on the next row
replace earnings = . if id == id[_n+1] & missing(earnings[_n+1])
This assumes that all individuals are indeed represented in each time period and that you have a unique id variable (id
) in your data set.

TheIceBear
- 2,912
- 9
- 23