Announcement

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

  • Adding more years in Panel

    Dear Statalist Users,

    I would like to add more years in my dataset. I have used "fillin" command but it did not work.

    I hope you can help me.

    I have 81 cities and I observe each city in each year from 2003 to 2018 once. Each city has a unique identifier (i.e., variable plate). The variable plate ranges from 1 to 81. For example 1 denotes city "Adana". As you can see from the example data, I observe Adana (i.e., plate 1) in 2003, 2004, 2005,.., 2018. However, I need to add more years: 1998, 1999, 2000, 2001, and 2002. In the end, for example, I would like to observe city Adana (plate 1) in 1998, 1999, 2000, ..., 2018.

    Thank you very much in advance.






    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte plate str15 city int child_birth_year float z_refugee_share
    1 "Adana"    2003 -.16672547
    1 "Adana"    2004 -.16672547
    1 "Adana"    2005 -.16672547
    1 "Adana"    2006 -.16672547
    1 "Adana"    2007 -.16672547
    1 "Adana"    2008 -.16672547
    1 "Adana"    2009 -.16672547
    1 "Adana"    2010 -.16672547
    1 "Adana"    2011 -.16672547
    1 "Adana"    2012 -.16672547
    1 "Adana"    2013 -.02810832
    1 "Adana"    2014   .2721727
    1 "Adana"    2015   .8131932
    1 "Adana"    2016   .9066704
    1 "Adana"    2017   .9490147
    1 "Adana"    2018  1.2135105
    2 "Adiyaman" 2003 -.16672547
    2 "Adiyaman" 2004 -.16672547
    2 "Adiyaman" 2005 -.16672547
    2 "Adiyaman" 2006 -.16672547
    2 "Adiyaman" 2007 -.16672547
    2 "Adiyaman" 2008 -.16672547
    2 "Adiyaman" 2009 -.16672547
    2 "Adiyaman" 2010 -.16672547
    2 "Adiyaman" 2011 -.16672547
    2 "Adiyaman" 2012 -.16672547
    2 "Adiyaman" 2013  .09111027
    2 "Adiyaman" 2014   .6769764
    2 "Adiyaman" 2015  .39182165
    2 "Adiyaman" 2016   .4605239
    2 "Adiyaman" 2017   .4996558
    2 "Adiyaman" 2018   .5800445
    3 "Afyon"    2003 -.16672547
    3 "Afyon"    2004 -.16672547
    3 "Afyon"    2005 -.16672547
    3 "Afyon"    2006 -.16672547
    3 "Afyon"    2007 -.16672547
    3 "Afyon"    2008 -.16672547
    3 "Afyon"    2009 -.16672547
    3 "Afyon"    2010 -.16672547
    3 "Afyon"    2011 -.16672547
    3 "Afyon"    2012 -.16672547
    3 "Afyon"    2013 -.16672547
    3 "Afyon"    2014 -.15601103
    3 "Afyon"    2015 -.10584597
    3 "Afyon"    2016 -.07713125
    3 "Afyon"    2017 -.06103815
    3 "Afyon"    2018 -.03937353
    4 "Agri"     2003 -.16672547
    4 "Agri"     2004 -.16672547
    4 "Agri"     2005 -.16672547
    4 "Agri"     2006 -.16672547
    4 "Agri"     2007 -.16672547
    4 "Agri"     2008 -.16672547
    4 "Agri"     2009 -.16672547
    4 "Agri"     2010 -.16672547
    4 "Agri"     2011 -.16672547
    4 "Agri"     2012 -.16672547
    4 "Agri"     2013 -.16672547
    4 "Agri"     2014 -.16396767
    4 "Agri"     2015 -.14477333
    4 "Agri"     2016 -.14309107
    4 "Agri"     2017 -.13892677
    4 "Agri"     2018  -.1353968
    5 "Amasya"   2003 -.16672547
    5 "Amasya"   2004 -.16672547
    5 "Amasya"   2005 -.16672547
    5 "Amasya"   2006 -.16672547
    5 "Amasya"   2007 -.16672547
    5 "Amasya"   2008 -.16672547
    5 "Amasya"   2009 -.16672547
    5 "Amasya"   2010 -.16672547
    5 "Amasya"   2011 -.16672547
    5 "Amasya"   2012 -.16672547
    5 "Amasya"   2013 -.16672547
    5 "Amasya"   2014 -.16226056
    5 "Amasya"   2015   -.160296
    5 "Amasya"   2016  -.1570366
    5 "Amasya"   2017  -.1487765
    5 "Amasya"   2018 -.14127544
    6 "Ankara"   2003 -.16672547
    6 "Ankara"   2004 -.16672547
    6 "Ankara"   2005 -.16672547
    6 "Ankara"   2006 -.16672547
    6 "Ankara"   2007 -.16672547
    6 "Ankara"   2008 -.16672547
    6 "Ankara"   2009 -.16672547
    6 "Ankara"   2010 -.16672547
    6 "Ankara"   2011 -.16672547
    6 "Ankara"   2012 -.16672547
    6 "Ankara"   2013 -.16672547
    6 "Ankara"   2014  -.0727472
    6 "Ankara"   2015  .00234771
    6 "Ankara"   2016  .04360104
    6 "Ankara"   2017  .08465073
    6 "Ankara"   2018  .13453442
    7 "Antalya"  2003 -.16672547
    7 "Antalya"  2004 -.16672547
    7 "Antalya"  2005 -.16672547
    7 "Antalya"  2006 -.16672547
    end




  • #2
    Would you please tell us why -fillin- "didn't work" at a high level and provide the exact line of code you used along with the error message?

    Comment


    • #3
      Wait a second, I think you want -tsfill- for this instead of -fillin-, right? Or am I missing something?

      Comment


      • #4
        No, this is not a job for -tsfill-; that's used to fill gaps in the time-series (within panels in the case of panel data), but it does not "extrapolate" beyond the existing time values.

        This is a job for -fillin-. We aren't told how O.P. tried to use it, but apparently he did not get it right.

        Here's how I would do it. -fillin- rectangularizes the data set. So all that is needed in this case is to create some new observations for any city (the first one is the most convenient) for the years 1998 through 2002. Then -fillin- does the rest.
        Code:
        insobs 5, before(1)
        replace plate = 1 in 1/5
        replace child_birth_year = 1998 + _n - 1 in 1/5
        fillin plate child_birth_year
        by plate (city), sort: replace city = city[_N]
        xtset plate child_birth_year

        Comment


        • #5
          Originally posted by Clyde Schechter View Post
          No, this is not a job for -tsfill-; that's used to fill gaps in the time-series (within panels in the case of panel data), but it does not "extrapolate" beyond the existing time values.

          This is a job for -fillin-. We aren't told how O.P. tried to use it, but apparently he did not get it right.

          Here's how I would do it. -fillin- rectangularizes the data set. So all that is needed in this case is to create some new observations for any city (the first one is the most convenient) for the years 1998 through 2002. Then -fillin- does the rest.
          Code:
          insobs 5, before(1)
          replace plate = 1 in 1/5
          replace child_birth_year = 1998 + _n - 1 in 1/5
          fillin plate child_birth_year
          by plate (city), sort: replace city = city[_N]
          xtset plate child_birth_year
          Dear Schechter,

          It perfectly worked the way I wanted. Thanks a lot!

          Comment

          Working...
          X