Announcement

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

  • Dummy variables with a range

    Hello everyone,

    I need to create a dummy variable for industry production for when the cycle is in bust and boom and I'm having a brain fart.

    for example i created

    generate DUM1990 = 0
    replace DUM1990 = 1 if (Month>tm(1990m6) & Month<tm(1991m3))

    But if specify the dummy variable to be for month it wont have an effect on my variable Industry production or will it?

    If it doesn't how do i specify that my variable industry production takes the values of 1 between those dates and a value of 0 for all other dates?

  • #2
    I don't follow what the question is here. This illustrates a direct way to get an indicator or dummy variable that is 1 in an interval and 0 outside it. Your code looks equivalent.

    Code:
    clear
    set obs 24 
    gen Month = tm(1989m12) + _n
    format Month %tm 
    
    * you start here 
    gen Dummy = inrange(Month, tm(1990m7), tm(1991m2))
    
    list, sep(12)
    
        +-----------------+
         |   Month   Dummy |
         |-----------------|
      1. |  1990m1       0 |
      2. |  1990m2       0 |
      3. |  1990m3       0 |
      4. |  1990m4       0 |
      5. |  1990m5       0 |
      6. |  1990m6       0 |
      7. |  1990m7       1 |
      8. |  1990m8       1 |
      9. |  1990m9       1 |
     10. | 1990m10       1 |
     11. | 1990m11       1 |
     12. | 1990m12       1 |
         |-----------------|
     13. |  1991m1       1 |
     14. |  1991m2       1 |
     15. |  1991m3       0 |
     16. |  1991m4       0 |
     17. |  1991m5       0 |
     18. |  1991m6       0 |
     19. |  1991m7       0 |
     20. |  1991m8       0 |
     21. |  1991m9       0 |
     22. | 1991m10       0 |
     23. | 1991m11       0 |
     24. | 1991m12       0 |
         +-----------------+

    Comment

    Working...
    X