Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: replacing missing cases


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: replacing missing cases
Date   Tue, 4 Feb 2003 13:41:29 -0000

Ronnie Babigumira

> I am running regressions on sub-samples (diffrent years) of
> a data set. I
> would like to add the crimerate (lcrmrte) of 1986 to a
> regression for 1987
> so I generate lcrmte86 which is the rate for 1986 however
> as u can see, its
> missing if the year is not 1986 (which makes sense). I
> would now like to
> fill in the missing values with the county value for 1986
> (such that lcrmte
> = -3.359507 when county == 1 and so forth).
>
> How do I replace the missing cases in lcrmte86 with the
> county value given.
>
>   lcrmrte   lcrmte86     county       year
> -3.221757          .          1         81
> -3.261134          .          1         82
> -3.496449          .          1         83
>  -3.36027          .          1         84
> -3.308445          .          1         85
> -3.359507  -3.359507          1         86
> -3.335309          .          1         87
> -4.110956          .          3         81
> -3.959896          .          3         82
> -4.189807          .          3         83
>  -4.29313          .          3         84
>  -4.41997          .          3         85
> -4.342945  -4.342945          3         86
> -4.182966          .          3         87
> -4.673753          .          5         81
> -4.396296          .          5         82
>  -4.35781          .          5         83
> -4.280922          .          5         84
> -4.384005          .          5         85
> -4.251806  -4.251806          5         86
> -4.345864          .          5         87
> -3.820543          .          7         81
> -4.052395          .          7         82
> -3.720948          .          7         83
> -3.801224          .          7         84
> -3.705627          .          7         85
> -3.724378  -3.724378          7         86
> -3.621101          .          7         87
>

One way to do it:

. bysort county (lcrmte86) : replace lcrmte86 = lcrmte86[1] if
missing(lcrmte86)

Nick
n.j.cox@durham.ac.uk

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index