Announcement

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

  • Adding 4 years before and after for each ID

    Hello,
    My data looks as below.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int ID str8 Country int Year str3 Type
    774 "Albania"  2006 "ARF"
    760 "Albania"  2011 "ARF"
    507 "Chile"    2014 "BCA"
    708 "Colombia" 2019 "BCA"
    650 "Colombia" 2022 "ARF"
    end
    For each ID I want to add 4 years before and 4 years after. All the information except for the year stays the same. An example of what I want is given below.
    ID Country Year Type
    774 Albania 2002 ARF
    774 Albania 2003 ARF
    774 Albania 2004 ARF
    774 Albania 2005 ARF
    774 Albania 2006 ARF
    774 Albania 2007 ARF
    774 Albania 2008 ARF
    774 Albania 2009 ARF
    774 Albania 2010 ARF
    760 Albania 2007 ARF
    760 Albania 2008 ARF
    760 Albania 2009 ARF
    760 Albania 2010 ARF
    760 Albania 2011 ARF
    760 Albania 2012 ARF
    760 Albania 2013 ARF
    760 Albania 2014 ARF
    760 Albania 2015 ARF
    507 Chile 2010 BCA
    507 Chile 2011 BCA
    507 Chile 2012 BCA
    507 Chile 2013 BCA
    507 Chile 2014 BCA
    507 Chile 2015 BCA
    507 Chile 2016 BCA
    507 Chile 2017 BCA
    507 Chile 2018 BCA
    I would appreciate any help on how to do this. Many thanks in advance.

  • #2
    Code:
    expand 9
    by ID (Year), sort: replace Year = Year - 5 + _n
    sort ID Year

    Comment


    • #3
      This worked. Thank you very much!

      Comment

      Working...
      X