Announcement

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

  • How to replace a missing value with a value in certain row

    I need to fill up the missing values for the variable (v1). The variables are {country, v1, v2}

    I have sporadic missing values in v1, but v1 and v2 have high correlation, so I can fill up v1 based on the order statistics of v2.
    For example, I want to replace v1[1] to v2 if v2_rank == 1

    I tried
    replace v1 = v2[v2_rank] if v1 == .
    replace v1 = v2[_v2_rank] if v1 == .



    But it does not work...


    country v1 v2 v1_rank v2_rank
    SG . 11 . 1
    NL 10 10 1 2
    HK 9 9 2 3
    GB 8 8 3 4








  • #2
    Use dataex please. I need to see your actual data, otherwise I can't help you. "Does not work" is super vague.

    Comment


    • #3

      Code:
      replace v1 = v2[v2_rank] if v1 == .
      and
      Code:
      replace v1 = v2[_v2_rank] if v1 == .
      But none of them works...

      country v1 v2 v1_rank v2_rank
      SG . 11 . 1
      NL 10 10 1 2
      HK 9 9 2 3
      GB 8 8 3 4

      Comment


      • #4
        Code:
        replace v1 = v2 if v1 == .

        Comment

        Working...
        X