Announcement

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

  • How to mipolate without a group id or a index

    Hello,

    I have a Stata coding question. Below is a made up dataset with only two variables, state and city.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str10 state str13 city
    "california" "san diego"    
    ""           "san francisco"
    ""           "santa rosa"  
    ""           "los angeles"  
    "texas"      "houston"      
    ""           "dallas"      
    ""           "austin"      
    "new york"   "rochester"    
    ""           "albany"      
    end

    The state variable has missing values. I want to carry forward the values so that it looks like this.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str10 state str13 city
    "california" "san diego"    
    "california" "san francisco"
    "california" "santa rosa"  
    "california" "los angeles"  
    "texas"      "houston"      
    "texas"      "dallas"      
    "texas"      "austin"      
    "new york"   "rochester"    
    "new york"   "albany"      
    end


    I tried using the mipolate package that I found from this entry. I noticed that to use this package, I need a group id variable and a variable to index each group. Unfortunately, my dataset only has two variables. I don't want to manually fill in the state variable. Does anyone have a more efficient solution?
    https://www.statalist.org/forums/for...-interpolation

  • #2
    mipolate from SSC isn't the best solution here if only for the reason you mention, lack of an appropriate identifier.

    Code:
    replace state = state[_n-1] if missing(state)
    should work fine if your data all resemble your example. See also a longstanding FAQ https://www.stata.com/support/faqs/d...issing-values/ and a miniature tutorial https://journals.sagepub.com/doi/pdf...6867X231196519

    Comment


    • #3
      Thanks Nick. This works great.

      Comment

      Working...
      X