Announcement

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

  • I want to create 5-year-Intervals in my Year-Variable

    Hello out there,

    I have a dataset spanning with a lot of different variables, one of them being, "year", spanning from 1948 - 2016

    I am estimating a gravity model and in relations hereto i want to make 5-year intervals for this variable.
    i want to look at year 1948, 1953, 1958 etc..

    So i guess i want to drop all the years that are not part of my interval but i am afraid to drop relevant data.

    Anyone have an idea on how to do this?

    Kind Regards J.S.

  • #2
    Code:
    clear
    set obs 69
    gen year = _n + 1947
    
    gen tokeep = 0
    foreach x of numlist 1948(5)2016{
        replace tokeep = 1 if year == `x'
    }
    
    keep if tokeep == 1
    Results:
    Code:
         +---------------+
         | year   tokeep |
         |---------------|
      1. | 1948        1 |
      2. | 1953        1 |
      3. | 1958        1 |
      4. | 1963        1 |
      5. | 1968        1 |
      6. | 1973        1 |
      7. | 1978        1 |
      8. | 1983        1 |
      9. | 1988        1 |
     10. | 1993        1 |
     11. | 1998        1 |
     12. | 2003        1 |
     13. | 2008        1 |
     14. | 2013        1 |
         +---------------+

    Comment


    • #3
      You could just note that dividing by 5 leaves remainder 3.

      Code:
      . di mod(1948, 5)
      3
      
      . di mod(1953, 5)
      3
      So, the criterion could be


      Code:
      keep if mod(year, 5) == 3
      or even

      Code:
      keep if inlist(mod(year, 10). 3. 8)


      Comment


      • #4
        Thank u so much for the answers, it worked perfecttly!
        And thanks for the heads up Nick, that should of course be noted

        Comment

        Working...
        X