Dear all,
I want calculate the mean of the hb0900 variable (property valuation) between 1942 and 2016 and years do not always run sequentially. A sample of my survey dataset looks like this:
My code is below and the he problem is that every time the mi estimate command runs the replace meanhb0800 replaces all 1,004 observations but I want it to replace it each observation at a time so I can have the meanhb0800 containing the mean for each respective year. {The mi estimate commands takes care of the missing observations so don't worry about that part.)
gen meanhb0800 = .
forval i = 1956/2016 {
mi estimate, esampvaryok vceok: svy: mean hb0800 if hb0700==`i'
scalar b_ih = el(e(b_mi),1,1)
replace meanhb0800 = el(e(b_mi),1,1)
}
Any help would be appreciated.
Ilias
I want calculate the mean of the hb0900 variable (property valuation) between 1942 and 2016 and years do not always run sequentially. A sample of my survey dataset looks like this:
hb0700 | hb0800 |
2008 | 130000 |
2007 | 314465 |
1994 | 30000.5 |
1961 | 20000 |
1993 | 30000 |
gen meanhb0800 = .
forval i = 1956/2016 {
mi estimate, esampvaryok vceok: svy: mean hb0800 if hb0700==`i'
scalar b_ih = el(e(b_mi),1,1)
replace meanhb0800 = el(e(b_mi),1,1)
}
Any help would be appreciated.
Ilias
Comment