Announcement

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

  • Panel data- replacing missing individual values with the values of another individual, by time

    Hi folks- I have a panel dataset that looks roughly like the example below. In my dataset, I have 5 years of observations, by day, for each individual. In this example, I've only included two months per year to keep it simple.
    I'm trying to replace some individuals' missing values with the same time values as a specific other individual. In this example, indivual 3 is missing values of "measurement", and I want to replace these with the Individual 1's values of "measurement", matched by time. So, my current dataset looks like this:


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte individual int year byte(month measurement)
    1 2010 1  2
    1 2010 2  9
    1 2011 1  7
    1 2011 2  5
    1 2012 1  5
    1 2012 2  4
    2 2010 1 12
    2 2010 2  2
    2 2011 1 10
    2 2011 2  7
    2 2012 1  6
    2 2012 2  3
    3 2010 1  .
    3 2010 2  5
    3 2011 1  7
    3 2011 2  .
    3 2012 1  .
    3 2012 2  9
    end

    And I need it to look like the example below. Any help would be greatly appreciated! Thanks.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte individual int year byte(month measurement)
    1 2010 1  2
    1 2010 2  9
    1 2011 1  7
    1 2011 2  5
    1 2012 1  5
    1 2012 2  4
    2 2010 1 12
    2 2010 2  2
    2 2011 1 10
    2 2011 2  7
    2 2012 1  6
    2 2012 2  3
    3 2010 1  2
    3 2010 2  5
    3 2011 1  7
    3 2011 2  5
    3 2012 1  5
    3 2012 2  9
    end
    Last edited by Greg Boudreaux; 02 May 2021, 16:04.

  • #2
    Hi Greg,

    Does something like the following work, it might require tweaking, I have shown how to replace 3 with 1 but I am not sure what the general rule you want to apply is:

    Code:
    bysort year month (individual): replace measurement = measurement[1] if individual==3
    Best,
    Rhys

    Comment

    Working...
    X