Announcement

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

  • Ttest with categorical varaibles

    HI, I wanted to know if it is possible to run ttests in order to calculate the difference between the means, also with categorical variables and dummy variables?
    At the moment I am using only continuous variables and a dummy one after the "by":
    e.g. ttest var_continuous, by(dummy_var)
    but I would need to do the same also with categoricals and dummies instead of the continuous variables.
    Is it possible? or is there another method to look at the difference between categorical and dummy variables of two different groups?
    Thank you in advance

  • #2
    Alice:
    -ttest- implies a comparison between continuous variables.
    If you want to investigate the effect on s (two-level) categorical variable (regressand) caused by a categorical regressand (by the way, I do not understand the difference between categorical and dummy variables, that sounds as the very same thing to me), you may want to consider .logit-:
    Code:
    . use "C:\Program Files\Stata17\ado\base\a\auto.dta"
    (1978 automobile data)
    
    . logit foreign i.rep78
    
    note: 1.rep78 != 0 predicts failure perfectly;
          1.rep78 omitted and 2 obs not used.
    
    note: 2.rep78 != 0 predicts failure perfectly;
          2.rep78 omitted and 8 obs not used.
    
    note: 5.rep78 omitted because of collinearity.
    Iteration 0:   log likelihood = -38.411464  
    Iteration 1:   log likelihood = -27.676628  
    Iteration 2:   log likelihood = -27.446054  
    Iteration 3:   log likelihood = -27.444671  
    Iteration 4:   log likelihood = -27.444671  
    
    Logistic regression                                     Number of obs =     59
                                                            LR chi2(2)    =  21.93
                                                            Prob > chi2   = 0.0000
    Log likelihood = -27.444671                             Pseudo R2     = 0.2855
    
    ------------------------------------------------------------------------------
         foreign | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
           rep78 |
              1  |          0  (empty)
              2  |          0  (empty)
              3  |  -3.701302   .9906975    -3.74   0.000    -5.643033   -1.759571
              4  |  -1.504077   .9128709    -1.65   0.099    -3.293271    .2851168
              5  |          0  (omitted)
                 |
           _cons |   1.504077    .781736     1.92   0.054    -.0280969    3.036252
    ------------------------------------------------------------------------------
    
    .
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment

    Working...
    X