Announcement

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

  • Help With Linear Interpolation


    Dear Stata Members

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str5 country int year float variable
    "China" 1999        .
    "China" 2000        .
    "China" 2001     .525
    "China" 2002        .
    "China" 2003        .
    "China" 2004        .
    "China" 2005        .
    "China" 2006        .
    "China" 2007        .
    "China" 2008   .48669
    "China" 2009        .
    "China" 2010        .
    "China" 2011        .
    "China" 2012        .
    "China" 2013 .6152174
    "China" 2014        .
    "China" 2015        .
    "China" 2016        .
    "China" 2017        .
    "China" 2018 .6485507
    "China" 2019        .
    "USA"   1999 .3591667
    "USA"   2000        .
    "USA"   2001        .
    "USA"   2002        .
    "USA"   2003        .
    "USA"   2004        .
    "USA"   2005        .
    "USA"   2006 .3931145
    "USA"   2007        .
    "USA"   2008        .
    "USA"   2009        .
    "USA"   2010        .
    "USA"   2011 .3781362
    "USA"   2012        .
    "USA"   2013        .
    "USA"   2014        .
    "USA"   2015        .
    "USA"   2016        .
    "USA"   2017 .3959938
    "USA"   2018        .
    "USA"   2019        .
    end

    Based on the above sample data, I would like to interpolate the missing values for the variable. My desire is based on an article which uses similar data saying "We interpolated linearly to fill in this variable for the years between the two adjacent surveys". Am I making sense in my request?

  • #2
    Code:
    help ipolate 
    
    bysort country: ipolate variable year, gen(wanted)

    Comment


    • #3
      Thanks a lot Nick Cox. Can I ask you a follow-up question? What is the principle behind this linear interpolation (I read the file and the formula is similar to one that uses for finding the co-ordinates) and is it okay to linear interpolation for filling missing values in this manner (I cited a paper, but this paper doesn't explain why linear interpolation makes sense in general). Any thoughts can help me know what I am dealing with.

      Comment


      • #4
        The principle behind linear interpolation is that it may make sense to assume that the pattern of change is linear between known data points! No more, no less.

        For defined functions of the kind met in elementary mathematics this is often but not invariably true: consider interpolating y = 1/x near x == 0.

        For empirical data the presumption is that of small, gradual changes between data points.

        Comment

        Working...
        X