Announcement

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

  • generating N dummies for each value in variable

    Good morning,

    I need to generate a categorical variable for each of these entries:


    Code:
      number of |
       tutoring |
          first |
       semester |      Freq.     Percent        Cum.
    ------------+-----------------------------------
              0 |      3,455       89.37       89.37
              1 |          8        0.21       89.58
              2 |          6        0.16       89.73
              3 |         10        0.26       89.99
              4 |         13        0.34       90.33
              5 |         12        0.31       90.64
              6 |         10        0.26       90.89
              7 |         16        0.41       91.31
              8 |         13        0.34       91.65
              9 |         19        0.49       92.14
             10 |         23        0.59       92.73
             11 |         21        0.54       93.27
             12 |         28        0.72       94.00
             13 |         27        0.70       94.70
             14 |         32        0.83       95.53
             15 |         24        0.62       96.15
             16 |         23        0.59       96.74
             17 |         28        0.72       97.47
             18 |         17        0.44       97.90
             19 |          6        0.16       98.06
             20 |          5        0.13       98.19
             21 |         10        0.26       98.45
             22 |          6        0.16       98.60
             23 |          6        0.16       98.76
             24 |          8        0.21       98.97
             25 |          4        0.10       99.07
             26 |          3        0.08       99.15
             27 |          3        0.08       99.22
             28 |          3        0.08       99.30
             29 |          4        0.10       99.41
             30 |          4        0.10       99.51
             31 |          2        0.05       99.56
             32 |          2        0.05       99.61
             33 |          1        0.03       99.64
             35 |          2        0.05       99.69
             37 |          3        0.08       99.77
             41 |          2        0.05       99.82
             42 |          1        0.03       99.84
             43 |          2        0.05       99.90
             44 |          1        0.03       99.92
             45 |          1        0.03       99.95
             46 |          1        0.03       99.97
             48 |          1        0.03      100.00
    ------------+-----------------------------------
          Total |      3,866      100.00
    
    . gen i.Tut_20161
    the variable is called "Tut_20161"

    I think it should be forvalues , I simply can't do loops with forvalues.


  • #2
    You don't usually need that many indicators (you say "dummies"). Just use factor variable notation in your model fit command. But if you do really need those variables, you don't need a loop of any kind. Use tabulate with a generate() option.

    More discussion at https://journals.sagepub.com/doi/abs...36867X19830921 but the paragraph above is, I think, all you need to know.

    Comment


    • #3
      Originally posted by Nick Cox View Post
      You don't usually need that many indicators (you say "dummies"). Just use factor variable notation in your model fit command. But if you do really need those variables, you don't need a loop of any kind. Use tabulate with a generate() option.

      More discussion at https://journals.sagepub.com/doi/abs...36867X19830921 but the paragraph above is, I think, all you need to know.
      Thank you, infinitely, I didn't know you could generate as option of tab...

      Matteo

      Comment


      • #4
        Good, but Just use factor variable notation in your model fit command remains the main advice.

        Comment

        Working...
        X