Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • mi estimate and loop

    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:
    hb0700 hb0800
    2008 130000
    2007 314465
    1994 30000.5
    1961 20000
    1993 30000
    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

  • #2
    What about
    Code:
    ...
    replace meanhb0800 = el(e(b_mi),1,1)  if hb0700==`i'
    ...
    ?

    Comment


    • #3
      I'm not sure I follow what you want here, but I think what you need to do is add -if hb0700 == `i'- to your -replace meanhb0800 = ...- command.

      Added: Crossed with #2.

      Comment


      • #4
        Yes, your suggestion worked.
        Thank you both!
        Ilias

        Comment

        Working...
        X