I'm working on longitudinal data that look like the following:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input byte id double x 1 5.2 1 5.4 1 . 1 5.3 1 5 2 4.7 2 . 2 . 2 4.8 2 4.6 3 2 3 2.1 3 2.4 3 . 3 2.3 end
Code:
bys id: gen d_x=d.x
For instance, with id==2, 4.8 should be first differenced with 4.7, being the last available observation, regardless of the number of missing values in between.
Many thanks for your help!
0 Response to Generate first difference using last available obs if missing
Post a Comment