Announcement

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

  • Filling missing data upward on panel time-series

    I have a panel time series where i need to fill the missing data upward based on the data for the latest year.
    i tried replace dummy=dummy[n+1] but it only fills the second to last year data. I need to replicate this dummy for all years in each panel.

    Thanks in advance!
    Attached Files

  • #2
    Code:
    gsort ifs_code -year
    by ifs_code: replace dummy = dummy[_n-1] if missing(dummy)
    sort ifs_code year
    Since you posted your data as a screenshot, which is useless for importing to Stata and testing code, this code is untested. It may contain typos, unbalanced parens/brackets etc. In the future, to get a more helpful response, post your data example in a helpful way: use the -dataex- command. Run -ssc install dataex- to get it, and then run -help dataex- to read the instructions for using it. By using -dataex- you will enable those who want to help you to create a complete and faithful replica of your Stata example with a simple copy/paste operation, thereby enabling them to try out their code and verify that it runs correctly with data like yours.

    Comment


    • #3
      solved! thanks!!!

      Comment


      • #4
        In addition to Clyde's excellent advice, people interested in this may wish to read

        1. FAQ https://www.stata.com/support/faqs/d...issing-values/ Among other things, that FAQ explains Clyde's method and indeed why the method in #1 didn't work as hoped.

        2. The command mipolate (SSC) bundles together several of the simplest interpolation methods. The original announcement was

        https://www.statalist.org/forums/for...-interpolation

        and mipolate (fortunately, but not fortuitously) is a distinctive search term for posts mentioning it.

        Comment

        Working...
        X