Announcement

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

  • please help me understand var1##var2 through mathematical writing

    Hi all, I've been using the indicators command in stata to avoid generating the dummies or forgetting to plug one in the regression, but I'm afraid I've started to lose grip with what it actually does virtually now that I have to generate them for other purposes. It would really help me if someone could explain to me in mathematical terms what they correspond to:

    For a qualifications variable with 6 categories, this regression -reg LogIncome Age ib4.Qualification- would correspond to
    the following:
    (that's a 6)

    For the same qualification variable interacting with a 2-categories Male variable, would this regression:
    -reg LogIncome Age Male##ib4.Qualification- correspond to the following?



    I know this may seem futile...I've been on stata so long im starting to forget my stats. (forgive my pic sizing too)

    ps: any advice on how to correctly generate the Male#ib4.Qualification dummies is welcomed too.

  • #2
    Solal:
    your first code:
    Code:
    reg LogIncome Age ib4.Qualification
    means that, as far as the categorical variable is concerned, you have chosen the level # 4 as the reference category.

    Your second code:
    Code:
    reg LogIncome Age Male##ib4.Qualification
    means that you included both the main conditional effect of the categorical variables -Male- (if -Male- actually has two levels only, the -i.- prefix is redundant; that said, I think it is a good habit to include it anyhow, just to get more and more familiar with -fvvarlist- notation) and -Qualification-; again, for the latter predictor, you have chosen the level # 4 as the reference category.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Thanks Carlo! So the mathematical writing is correct then? I'm especially worried about the SUMBeta(Man x Qualification) notation.

      On another note, I need to generate the interactive variable in stata in order to run a f test (could not figure out how to use the virtually created values by the ## command to run -test Male##ib4Qualification=0-

      I would need to run this instead I think: -test Male1_Qualification1=Male1_Qualification2=Male1_Qu alification3=Male1_Qualification5=Male1_Qualificat ion6=0-

      How would I go about generating the Male1_QualificationX dummies?
      Is it -gen Male_1Qualification1=Male*Qualification1- ?
      Or would it be -gen Male_1Qualification=(Male==1 & Qualification1==1) ?

      Thanks again

      Comment


      • #4
        Solal:
        I do hope that the following toy-example can be helpful:
        Code:
        . use "C:\Program Files\Stata16\ado\base\a\auto.dta"
        (1978 Automobile Data)
        
        . regress price i.foreign##i.rep78
        note: 1.foreign#1b.rep78 identifies no observations in the sample
        note: 1.foreign#2.rep78 identifies no observations in the sample
        note: 1.foreign#5.rep78 omitted because of collinearity
        
              Source |       SS           df       MS      Number of obs   =        69
        -------------+----------------------------------   F(7, 61)        =      0.39
               Model |    24684607         7  3526372.43   Prob > F        =    0.9049
            Residual |   552112352        61  9051022.16   R-squared       =    0.0428
        -------------+----------------------------------   Adj R-squared   =   -0.0670
               Total |   576796959        68  8482308.22   Root MSE        =    3008.5
        
        -------------------------------------------------------------------------------
                price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
        --------------+----------------------------------------------------------------
              foreign |
             Foreign  |   2088.167   2351.846     0.89   0.378     -2614.64    6790.974
                      |
                rep78 |
                   2  |   1403.125   2378.422     0.59   0.557    -3352.823    6159.073
                   3  |   2042.574   2204.707     0.93   0.358    -2366.011    6451.159
                   4  |   1317.056   2351.846     0.56   0.578    -3385.751    6019.863
                   5  |       -360   3008.492    -0.12   0.905    -6375.851    5655.851
                      |
        foreign#rep78 |
           Foreign#1  |          0  (empty)
           Foreign#2  |          0  (empty)
           Foreign#3  |  -3866.574   2980.505    -1.30   0.199    -9826.462    2093.314
           Foreign#4  |  -1708.278   2746.365    -0.62   0.536    -7199.973    3783.418
           Foreign#5  |          0  (omitted)
                      |
                _cons |     4564.5   2127.325     2.15   0.036      310.651    8818.349
        -------------------------------------------------------------------------------
        
        . mat list e(b)
        
        e(b)[1,18]
                     0b.           1.          1b.           2.           3.           4.           5.  0b.foreign#  0b.foreign#  0b.foreign#
                foreign      foreign        rep78        rep78        rep78        rep78        rep78     1b.rep78     2o.rep78     3o.rep78
        y1            0    2088.1667            0     1403.125    2042.5741    1317.0556         -360            0            0            0
        
             0b.foreign#  0b.foreign#  1o.foreign#  1o.foreign#   1.foreign#   1.foreign#  1o.foreign#            
               4o.rep78     5o.rep78     1b.rep78     2o.rep78      3.rep78      4.rep78     5o.rep78        _cons
        y1            0            0            0            0   -3866.5741   -1708.2778            0       4564.5
        
        . test 0b.foreign#1b.rep78=0b.foreign#2o.rep7=1.foreign#3.rep78=(1.foreign+1.foreign#4.rep78)
        
         ( 1)  0b.foreign#1b.rep78 - 0b.foreign#2o.rep78 = 0
         ( 2)  0b.foreign#1b.rep78 - 1.foreign#3.rep78 = 0
         ( 3)  - 1.foreign + 0b.foreign#1b.rep78 - 1.foreign#4.rep78 = 0
               Constraint 1 dropped
        
               F(  2,    61) =    0.88
                    Prob > F =    0.4211
        Same -test- as above , but with the -accumulate- option added (see -test- entry in Stata .pdf manual for more details):
        Code:
         test 0b.foreign#1b.rep78=0b.foreign#2o.rep7=1.foreign#3.rep78=(1.foreign+1.foreign#4.rep78), acc
        
         ( 1)  0b.foreign#1b.rep78 - 0b.foreign#2o.rep78 = 0
         ( 2)  0b.foreign#1b.rep78 - 1.foreign#3.rep78 = 0
         ( 3)  - 1.foreign + 0b.foreign#1b.rep78 - 1.foreign#4.rep78 = 0
         ( 4)  0b.foreign#1b.rep78 - 0b.foreign#2o.rep78 = 0
         ( 5)  0b.foreign#1b.rep78 - 1.foreign#3.rep78 = 0
         ( 6)  - 1.foreign + 0b.foreign#1b.rep78 - 1.foreign#4.rep78 = 0
               Constraint 1 dropped
               Constraint 4 dropped
               Constraint 5 dropped
               Constraint 6 dropped
        
               F(  2,    61) =    0.88
                    Prob > F =    0.4211
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment


        • #5
          Carlo, thank you very much for your example, it really helped! That's exactly what I was trying to do for the test.

          Last question, I'm still very unsure of myself when I write -reg LogIncome Age Male##ib4.Qualification- formally as:

          is the last term correct?

          Thanks again for you help,

          Kind regards,
          Solal

          Comment


          • #6
            Solal:
            yes, I think so.
            Be sure that level 4 is exactly what you want as reference category for -Qualification-.
            Kind regards,
            Carlo
            (Stata 19.0)

            Comment


            • #7
              Thank you Carlo, level 4 is indeed the reference I want. Have a good weekend!

              Comment


              • #8
                You, too!
                Kind regards,
                Carlo
                (Stata 19.0)

                Comment

                Working...
                X