[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: RE: Replacing Missing Values for multiple variables at one time?
In addition to looping across the variables, you could -collapse- and
-merge, update- to replace the missing values with average prices.
(I assume you meant price1, price2,... since variable names cannot start
with a number)
collapse (mean) price*, by(vil rd)
sort vil rd
sort vil rd
merge vil rd using `average', update
> -----Original Message-----
> From: email@example.com [mailto:owner-
> firstname.lastname@example.org] On Behalf Of JEFFREY ROSEN
> Sent: Saturday, July 08, 2006 4:47 PM
> To: email@example.com
> 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: