Statalist The Stata Listserver


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

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


From   JEFFREY ROSEN <[email protected]>
To   [email protected]
Subject   st: Replacing Missing Values for multiple variables at one time?
Date   Sat, 08 Jul 2006 16:46:47 -0500

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