Hi,
Here is a sample of my dataset:
My issue is that the household id (idhous) is missing for some individual id (idpers). For this reason, I ran this:
and this:
However, for some reasons, not all of the missing observations are replaced by the following or previous values for each value of idpers - which is what I want. But I noticed that when running the previous code many times, it eventually works.
That's why I would like to use a loop to do this faster, and to run it until Stata notices me "0 real changes made".
If there's any better option, I'd be glad to learn it as well.
Thank you.
Zsolt
Here is a sample of my dataset:
Code:
input long(idpers idhous) 4101 41 4101 41 4101 41 4101 . 4101 . 4101 . 4101 . 4101 . 4101 . 4101 . 4102 41 4102 41 4102 41 4102 41 4102 41 4102 41 4102 41 4102 41 4102 41 4102 41 4102 41 4102 41 4102 41 4102 41 4102 . 4102 . 4102 . 4102 . 4102 . 4102 . 4102 . 4103 41 4103 41 4103 41
Code:
bys idpers: replace idhous = idhous[_n-1] if missing(idhous)
Code:
bys idpers: replace idhous = idhous[_n+1] if missing(idhous)
That's why I would like to use a loop to do this faster, and to run it until Stata notices me "0 real changes made".
If there's any better option, I'd be glad to learn it as well.
Thank you.
Zsolt
Comment