Dear all,
I have a data set with multiple observations per person.
The variable "episode" has several missing values that I'm trying to "fill."
I want to carry forward a given number if the first number to reoccur after the missing value(s)
is the same number that is being carried forward, within the same person ( indicated by "ID").
So basically I want to fill in missing values if they are sandwhiched by the same number above and below.
There can be up to 30 consecutive rows with missing values within any given level of episode.
I have attached a sample of the data. The variable “new_var” shows what I am trying to do with “episode.”

It seems that carryforward (ssc install carryforward) might be the right thing to use here, though despite reading the help guide I cannot figure out how.
Does anyone see a quick way of doing this?
Thanks.
Karina
I have a data set with multiple observations per person.
The variable "episode" has several missing values that I'm trying to "fill."
I want to carry forward a given number if the first number to reoccur after the missing value(s)
is the same number that is being carried forward, within the same person ( indicated by "ID").
So basically I want to fill in missing values if they are sandwhiched by the same number above and below.
There can be up to 30 consecutive rows with missing values within any given level of episode.
I have attached a sample of the data. The variable “new_var” shows what I am trying to do with “episode.”
It seems that carryforward (ssc install carryforward) might be the right thing to use here, though despite reading the help guide I cannot figure out how.
Does anyone see a quick way of doing this?
Thanks.
Karina
Comment