Announcement

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

  • Panel data: Code for copying entry from one year to another year that has no data given that they have the same Name or ID

    Hi! This is my first post so I apologize in advance if I violate anything.


    I'm struggling to put what I want to ask into words so here's an illustration of my current (panel) data:
    Name Year Description
    A 2016 Oil
    B 2016 Oil
    C 2016 Gas
    D 2016 Wood
    A 2015
    B 2015
    C 2015
    A 2014
    B 2014
    So what I want to do is copy Description data to blank observations (in other years) that has exactly the same Name.
    Here's what I'm trying to achieve:
    Name Year Description
    A 2016 Oil
    B 2016 Oil
    C 2016 Gas
    D 2016 Wood
    A 2015 Oil
    B 2015 Oil
    C 2015 Gas
    A 2014 Oil
    B 2014 Oil
    The underlined entries under Description are the changes I want to be made.
    So what I'm trying to achieve is that a Description entry from a certain Year be copied to another year that has no Description, if the Name is the same.

    Notes*
    The entries under variable Name are not consistent across years (Name A may appear in Year 2016, 2015, and 2014, but not in 2013 and so on)
    I can manually tag them but the data is too big. I'm trying to fill 5000 entries, so I hope there is a way to automate it.

    Please let me know if more information is needed. Help would really be appreciated. Thank you!

  • #2
    I think this will do it for you:
    Code:
    bysort name (description): replace description = description[_N] if (trim(description) == "")

    Comment


    • #3
      Also, search for mentions of stripolate (SSC) e.g. http://www.statalist.org/forums/foru...-interpolation

      Comment


      • #4
        bysort name (description): replace description = description[_N] if (trim(description) == "")
        This made the job like magic.

        Also, thanks for sharing the stripolate. Might be really helpful on other works, but I'll need to study it more to use it effectively.

        Thank you both!

        Comment


        • #5
          At a guess, you're really Patrick not Patirck. If so, use the CONTACT US button to arrange a correction with the administrators.

          Comment


          • #6
            Oh I didn't notice! Sorry I guess I was too focused on the problem. Will do, thanks again.

            Comment

            Working...
            X