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

st: RE: RE: "imputing" missing observations


From   "McKenna, Timothy" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: "imputing" missing observations
Date   Tue, 25 May 2004 17:10:51 -0400

If you are not sure about whether each year is represented:

* find problems
gen elapsed_years = (year - year[_n-1]) if (zip == zip[_n-1])
expand elapsed_years
sort zip year
* replace the now bogus counts
replace count = 0 if ((elapsed_years > 1) & (year == year[_n-1]) & (zip == zip[_n-1]))
* get the year right
replace year = (year[_n-1] + 1) if (zip == zip[_n-1])

This does assume that the first year and last year for each zip code are observed with non zero counts.  Otherwise you would not be able to tell it is missing from the setup of the data.

-Tim

-----Original Message-----
From: Nick Cox [mailto:[email protected]]
Sent: Tuesday, May 25, 2004 4:49 PM
To: [email protected]
Subject: st: RE: "imputing" missing observations


So long as 1989 is a value for some other 
zip, you can 

fillin zip year 
replace count = 0 if _fillin 

Nick 
[email protected] 

Heather Taffet Gold, PhD 
 
> I've been looking all around, asking around, etc, and I can't 
> seem to find 
> out how to create new observations within my dataset.
> 
> Here are the specifics of my problem:
> I have counts of cases by zip code and year (one observation 
> with count for 
> each zip, and year). It happened that I ended up with "missing" 
> observations if the count of cases was zero in a year, so my 
> data look 
> something like this
> zip             year    count
> 06010           1986    1
> 06010           1987    2
> 06010           1988    2
> 06010           1990    7
> ...
> 
> How would I create a new observation for this zipcode in 1989 
> that has a 
> count of 0? I need to be able to create some lagged variables 
> by year and zip.

*
*   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/

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index