Announcement

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

  • Replacing Missing with a Specific Numerical Pattern

    Hi all -

    A friend of mine has a long dataset that looks like the following. Essentially, she wants to replace the missing variables based on the numlist 1/7, but only replace the missing variables and not change the values that already exist. We reshaped from long to wide and back again, and that did the trick, but I was wondering if there was another way. I was thinking it could be done using a conditional statement, but the code that I have written doesn't maintain the values that already exist. Which values go where doesn't matter, as long as wallet #1, for example, reads 6 7 and then any combination of the remaining values 1 2 3 4 5. Likewise for wallet #2.

    This is the code I was playing around with:

    by wallet, sort: replace month = cond(missing(month) & month != wallet[_n], _n, .)

    This is the data:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(wallet month)
    1 6
    1 7
    1 .
    1 .
    1 .
    1 .
    1 .
    2 .
    2 .
    2 .
    2 .
    2 3
    2 4
    2 5
    end

  • #2
    Patrick:
    welcome to this forum.
    Have you taken a look at -mi- suite in Stata .pdf manual?
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      You'll increase your chances of a useful answer by following the FAQ on asking questions.

      Implicit in Carlo's quite reasonable suggestion is that your recommended approach to missing data is not consistent with most recommended approaches to missing data. However, there may be something special about your data that make your approach reasonable. There are many approaches to missing data - mi, maximum likelihood with SEM, selection models, etc.

      There are many ways to do your calculation. It depends on what pattern you really want. For observation 1 on wallet 2, do you want a 7 or what?

      Comment

      Working...
      X