Announcement

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

  • Generate dummy variable for ranges of data

    I have a set of data that involves education levels (SCHOOLING) and ages (AGE). I want to generate a dummy variable to indicate whether or not an individual is within two years of the schooling level they should be at for their age. For example if a 9 year old should have 3 years of schooling, I want the dummy variable to be a 1 if they have 1 to 5 years of schooling and a 0 otherwise. How do I create such a dummy variable (AT_LEVEL) to indicate that SCHOOLING is within the range corresponding to AGE?

  • #2
    gen byte at_level=inrange(schooling,age-schooling-2,age-schooling+2)

    Comment


    • #3
      Code:
      clear
      input age schooling
      9 0
      9 1
      9 2
      9 3
      9 4
      9 5
      9 6
      end
      gen at_level = abs(schooling-age+6)<=2
      
      . list, clean
      
             age   school~g   atlevel 
        1.     9          0         0 
        2.     9          1         1 
        3.     9          2         1 
        4.     9          3         1 
        5.     9          4         1 
        6.     9          5         1 
        7.     9          6         0

      Comment

      Working...
      X