Announcement

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

  • Year Dummies for a duration

    Hello,

    I have data which is as below. ISO_O is the country, StartYear and EndYear are the years of commencement and finish of a political leader's reign. I would like to create a panel type structure and also generate a dummy for the years that the leader was in power.


    input str4 ISO_O int(StartYear EndYear) float Duration
    "ABW" 2017 2019 3
    "ARG" 2007 2015 9
    "AUS" 2010 2013 4
    "AUT" 2016 2017 2
    "AUT" 2004 2004 1
    end
    [/CODE]


    Therefore, for instance, for ABW the dummy would be '1' for years 2017,2018 and 2019 (i.e. 3 years, which is indicated by the duration variable too).

    Thanks in advance for your help and insights.

  • #2
    # Starting from 2000...
    Code:
    forval Z = 2000 / 2019 {
        gen InPower_`Z' = (StartYear >=`Z' & EndYear <=`Z')
    }

    Comment


    • #3
      Then check out help reshape for switching to a panel

      Comment


      • #4
        If I understand what is wanted correctly, a panel dataset can be produced like this:


        Code:
        input str4 ISO_O int(StartYear EndYear) float Duration
        "ABW" 2017 2019 3
        "ARG" 2007 2015 9
        "AUS" 2010 2013 4
        "AUT" 2016 2017 2
        "AUT" 2004 2004 1
        end
        
        bysort ISO_O (Start) : gen id = _n 
        expand Duration 
        bysort ISO_O id : gen Year = Start + _n - 1 
        
        list, sepby(ISO_O id) 
        
             +---------------------------------------------------+
             | ISO_O   StartY~r   EndYear   Duration   id   Year |
             |---------------------------------------------------|
          1. |   ABW       2017      2019          3    1   2017 |
          2. |   ABW       2017      2019          3    1   2018 |
          3. |   ABW       2017      2019          3    1   2019 |
             |---------------------------------------------------|
          4. |   ARG       2007      2015          9    1   2007 |
          5. |   ARG       2007      2015          9    1   2008 |
          6. |   ARG       2007      2015          9    1   2009 |
          7. |   ARG       2007      2015          9    1   2010 |
          8. |   ARG       2007      2015          9    1   2011 |
          9. |   ARG       2007      2015          9    1   2012 |
         10. |   ARG       2007      2015          9    1   2013 |
         11. |   ARG       2007      2015          9    1   2014 |
         12. |   ARG       2007      2015          9    1   2015 |
             |---------------------------------------------------|
         13. |   AUS       2010      2013          4    1   2010 |
         14. |   AUS       2010      2013          4    1   2011 |
         15. |   AUS       2010      2013          4    1   2012 |
         16. |   AUS       2010      2013          4    1   2013 |
             |---------------------------------------------------|
         17. |   AUT       2004      2004          1    1   2004 |
             |---------------------------------------------------|
         18. |   AUT       2016      2017          2    2   2016 |
         19. |   AUT       2016      2017          2    2   2017 |
             +---------------------------------------------------+

        You may already have a variable equivalent to id.

        I can't see that reshape applies here.

        Comment


        • #5
          Thank you for your reply Mike. The code above creates variables InPower_2000 till InPower_2019. However, it assigns 1 only to the countries in which StartYear and EndYear was the same. What I am looking for is the assignment of 1 to the years starting from StartYear and ending at EndYear i.e. the duration of being in power. I hope you have some more insights on this. Thanks in advance.

          Comment


          • #6
            Thank you Nick. This is exactly what was desired. Thank you very much!

            Comment

            Working...
            X