Announcement

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

  • Loop or tool to replace missing components of an aggregate

    I have an aggregate X that consists of components A + B + C + ...
    Suppose now that C is missing. If all others are available, I can use X - A - B - ... to obtain C.
    I can do the same thing now with every (missing) component (as long as there is only one). However, is there a faster way in Stata than using:
    replace A = X - B - C - ... if A == .
    replace B = X - A - C - ... if B == .
    and so on?

  • #2
    Code:
    local vars a b c
    egen xprime = rowtotal(`vars')
    foreach var of local vars {
        local othervars : list vars - var
        local othervars : subinstr local othervars " " ", ", all
        replace `var' = x - xprime if missing(var) & !missing(`othervars')
    }
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Many thanks!

      Comment

      Working...
      X