Announcement

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

  • copying a value within group

    Dear all,

    I need help about the following issue:

    Target: In my data there exists a variable, x. Within each group of observations identified by a unique id (call the variable boxnumber), x is missing for all but one observation. However, this value is not always in the same place or location; sometimes it is in the first raw of within the group and sometimes it is in row 3 or 4 etc. I want to assign this single nonmissing value of x (within each group) to all missing values of x within the group. That is, when I'm done, x is nonmissing for all observations and constant within boxnumber. This constantvalue of x (within id) remains unchanged for the original nonmissing values of x. Very similar question was asked in the following link. However, that solution suggested works only if this nonmissing value is always in the same order within the group. Thank you for your help. http://www.stata.com/statalist/archi.../msg00921.html http://www.stata.com/statalist/archi.../msg00923.html

  • #2
    mipolate (SSC) does this with its groupwise option.

    http://www.statalist.org/forums/foru...-interpolation

    If things are always exactly as you say, then you don't need that:

    Code:
    bysort id (x): replace x = x[1] if missing(x)
    would work too, as you just sort the non-missing value to first position in each group.

    A small advantage of mipolate is that it checks for different non-missing values in each group and bails out if any are found.

    Comment


    • #3
      Thank you very much for your help.

      Comment

      Working...
      X