-1

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.

1 Answers1

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