[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
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,
* For searches and help try: