I'm having trouble trying to fill in values for each person id (pid) in a long dataset. As you can see from my dataex example, some id numbers have a 1 for the variable "postdate." All of the rest are missing. For each pid with a 1 for postdate in any row, I would like to fill in the variable "postdate" with a 1 for the rest of the observations for that pid. So pid 4, 31, 32, 39 (etc.) below should have a 1 for "postdate" for all observations.
In the past I've used the code:
bysort pid (postdate): replace postdate=postdate[_N] if missing(postdate)
but this isn't resulting in any changes. Can someone help me figure out what I'm doing wrong?
Thank you,
Sarah
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(pid visitn postdate) 1 0 . 1 1 . 2 0 . 2 1 . 2 2 . 2 3 . 2 4 . 3 0 . 3 1 . 3 2 . 3 3 . 3 4 . 3 5 . 4 0 1 4 1 . 5 0 . 5 1 . 9 0 . 9 1 . 9 2 . 12 0 . 12 1 . 12 2 . 12 3 . 16 0 . 16 1 . 16 2 . 18 0 . 18 1 . 18 2 . 18 3 . 20 0 . 20 1 . 20 2 . 20 3 . 21 0 . 21 1 . 23 0 . 23 1 . 23 2 . 23 3 . 24 0 . 24 1 . 31 0 1 31 1 . 31 2 . 32 0 1 32 1 . 33 0 1 33 1 . 38 0 . 38 1 . 39 0 1 39 1 . 40 0 . 40 1 . 40 2 . 40 3 . 43 0 . 43 1 . 43 2 . 45 0 . 45 1 . 45 2 . 45 3 . 45 4 . 47 0 . 47 1 . 47 2 . 47 3 . 47 4 . 50 0 . 50 1 . 50 2 . 50 3 . 50 4 . 52 0 . 52 1 . 52 2 . 52 3 . 56 0 . 56 1 . 56 2 . 57 0 1 57 1 . 57 2 . 58 0 . 58 1 . 58 2 . 58 3 . 59 0 . 59 1 . 59 2 . 59 3 . 59 4 . 59 5 . 60 0 . 60 1 . 60 2 . 60 3 . end
0 Response to Trouble replacing missing values using bysort:replace
Post a Comment