Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Replacing Missing Values for multiple variables at one time?


From   "Scott Merryman" <[email protected]>
To   <[email protected]>
Subject   st: RE: Replacing Missing Values for multiple variables at one time?
Date   Sun, 9 Jul 2006 11:33:14 -0500

In addition to looping across the variables, you could -collapse- and
-merge, update- to replace the missing values with average prices.

For example:

(I assume you meant price1, price2,... since variable names cannot start
with a number)

preserve
tempfile average
collapse (mean) price*, by(vil rd)
sort vil rd
save `average'
restore
sort vil rd
merge vil rd using `average', update
drop _m
l


Scott

> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of JEFFREY ROSEN
> Sent: Saturday, July 08, 2006 4:47 PM
> To: [email protected]
> Subject: st: Replacing Missing Values for multiple variables at one time?
> 
> I'm working with a dataset that is sorted by households villages and
> rounds. The dataset is set up such that if a household made a purchase, a
> quantity and price was inputed. If there were no purchases, a missing
> value for price would be inputed. I would like to have the missing value
> be replaced with an average price from each village in each round.
> 
> So my dataset looks something like
> 
> hhold  village   rd   1price  2price 3price
> 1      1         1    5       .      3
> 1      1         2    3       2      4
> 2      1         1    .       3      4
> 2      1         2    1       3      .
> 3      2         1    3       2      4
> 3      2         2    2       3      .
> 4      2         1    4       5      2
> 4      2         2    .       .      2
> 
> What I've done in the the past if there was run:
> 
> bysort village rd: egen 1pricevil = mean(1price)
> replace 1price = 1pricevil if 1price == . & 1pricevil > 0
> 
> This is an easy code when I only have a couple prices, but I am working
> with a dataset that has over 50 variables that need to be changed. Is
> there some way to code it without having to enter in the above code for
> every variable?
> 
> Thanks in advance,
> 
> Jeff Rosen
> 
> 


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