Announcement

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

  • Comparing subcategories between groups

    Dear group members, I would like to ask whether you could suggest me a test for the following situation:

    I have two groups (A and B). Both groups have data for a categorical variable called X that has 3 categories. I would like to test whether the answers for each of the category are different between two groups. For example, I want to know if the number of observations in the first category is significantly greater in group A compared to the number of observations in the same category in group B.

  • #2
    Agnes:
    assunng that the levels of your depenedent variable are not ordered, you may want to consider -mlogit- and its post estimation suite of commands:
    Code:
    . use "C:\Program Files\Stata17\ado\base\a\auto.dta"
    (1978 automobile data)
    
    . tabulate rep78 foreign , chi2 col
    
    +-------------------+
    | Key               |
    |-------------------|
    |     frequency     |
    | column percentage |
    +-------------------+
    
        Repair |
        record |      Car origin
          1978 |  Domestic    Foreign |     Total
    -----------+----------------------+----------
             1 |         2          0 |         2
               |      4.17       0.00 |      2.90
    -----------+----------------------+----------
             2 |         8          0 |         8
               |     16.67       0.00 |     11.59
    -----------+----------------------+----------
             3 |        27          3 |        30
               |     56.25      14.29 |     43.48
    -----------+----------------------+----------
             4 |         9          9 |        18
               |     18.75      42.86 |     26.09
    -----------+----------------------+----------
             5 |         2          9 |        11
               |      4.17      42.86 |     15.94
    -----------+----------------------+----------
         Total |        48         21 |        69
               |    100.00     100.00 |    100.00
    
              Pearson chi2(4) =  27.2640   Pr = 0.000
    
    . mlogit rep78 i.foreign
    
    Iteration 0:   log likelihood = -93.692061  
    Iteration 1:   log likelihood = -80.470733  
    Iteration 2:   log likelihood = -78.986489  
    Iteration 3:   log likelihood = -78.794109  
    Iteration 4:   log likelihood = -78.748501  
    Iteration 5:   log likelihood = -78.738643  
    Iteration 6:   log likelihood = -78.736602  
    Iteration 7:   log likelihood = -78.736144  
    Iteration 8:   log likelihood = -78.736032  
    Iteration 9:   log likelihood = -78.736009  
    Iteration 10:  log likelihood = -78.736004  
    
    Multinomial logistic regression                         Number of obs =     69
                                                            LR chi2(4)    =  29.91
                                                            Prob > chi2   = 0.0000
    Log likelihood = -78.736004                             Pseudo R2     = 0.1596
    
    ------------------------------------------------------------------------------
           rep78 | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
    1            |
         foreign |
        Foreign  |   -13.6844   1986.817    -0.01   0.995    -3907.774    3880.405
           _cons |  -2.602702   .7328328    -3.55   0.000    -4.039028   -1.166376
    -------------+----------------------------------------------------------------
    2            |
         foreign |
        Foreign  |   -13.6844   993.4086    -0.01   0.989    -1960.729    1933.361
           _cons |  -1.216408   .4025404    -3.02   0.003    -2.005373    -.427443
    -------------+----------------------------------------------------------------
    3            |  (base outcome)
    -------------+----------------------------------------------------------------
    4            |
         foreign |
        Foreign  |   2.197466   .7698095     2.85   0.004     .6886674    3.706265
           _cons |  -1.098617   .3849011    -2.85   0.004    -1.853009   -.3442246
    -------------+----------------------------------------------------------------
    5            |
         foreign |
        Foreign  |    3.70116   .9906909     3.74   0.000     1.759442    5.642879
           _cons |  -2.602577     .73279    -3.55   0.000    -4.038819   -1.166335
    ------------------------------------------------------------------------------
    
    . test [5] ///I'm interested in testing if the coefficient -repairs=5- differsfrom zero for both domestic and foreign cars///
    
     ( 1)  [5]0b.foreign = 0
     ( 2)  [5]1.foreign = 0
           Constraint 1 dropped
    
               chi2(  1) =   13.96
             Prob > chi2 =    0.0002
    
    /// or, put differently:///
    
    . test [5]0b.foreign=[5]1.foreign
    
     ( 1)  [5]0b.foreign - [5]1.foreign = 0
    
               chi2(  1) =   13.96
             Prob > chi2 =    0.0002
    
    .
    Last edited by Carlo Lazzaro; 20 Nov 2022, 03:54.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Thank you so much! It worked perfectly.

      Comment

      Working...
      X