Announcement

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

  • Chi_square

    Dear all,
    Am using this command:

    Code:
    bys Shock: ta Shock Treatment, col Chi2
    However, no chi test gets registered. What can I do?

  • #2
    If I understood your query, when you use ‘by shock’ beforehand and wish to tabulate “by shock” as well, there won’t be more than one level of shocks, hence no chi2.
    Best regards,

    Marcos

    Comment


    • #3
      There are many shocks, I just coded the variable Shock. But I would like to get the chi square for every category of shock and every category og "Treatment" variable. I have also triedn this command and nothing comes out:
      Code:
      tab Shock Treatment if Shock==1, col chi2
      All these commands produce no chi square test

      Comment


      • #4
        I believe the explanation in #2 still applies, since you provided a similar example.

        That said, I gather this toy example will be helpful to clarify your doubt:

        Code:
        . sysuse auto
        (1978 Automobile Data)
        
        . gen highmpg = mpg > 27 & !missing(mpg)
        
        . tab foreign highmpg, chi2
        
                   |        highmpg
          Car type |         0          1 |     Total
        -----------+----------------------+----------
          Domestic |        47          5 |        52
           Foreign |        16          6 |        22
        -----------+----------------------+----------
             Total |        63         11 |        74
        
                  Pearson chi2(1) =   3.8087   Pr = 0.051
        
        . tab foreign highmpg if foreign ==1, chi2
        
                   |        highmpg
          Car type |         0          1 |     Total
        -----------+----------------------+----------
           Foreign |        16          6 |        22
        -----------+----------------------+----------
             Total |        16          6 |        22
        
        
        . by foreign, sort: tab foreign highmpg, chi2
        
        ------------------------------------------------------------------------------------------------------------
        -> foreign = Domestic
        
                   |        highmpg
          Car type |         0          1 |     Total
        -----------+----------------------+----------
          Domestic |        47          5 |        52
        -----------+----------------------+----------
             Total |        47          5 |        52
        
        
        ------------------------------------------------------------------------------------------------------------
        -> foreign = Foreign
        
                   |        highmpg
          Car type |         0          1 |     Total
        -----------+----------------------+----------
           Foreign |        16          6 |        22
        -----------+----------------------+----------
             Total |        16          6 |        22
        As we see, as long as we get only one level of a categorical variable, it would be nonsense (or impossible, if you will) to apply a chi-squared test, which means measures of assocation betwen categorical variables. In the last examples, where the chi-squared test is not feasible, there is only one level for the categorical variable.

        I hope to have helped.
        Last edited by Marcos Almeida; 13 Jun 2018, 05:12.
        Best regards,

        Marcos

        Comment


        • #5
          I see the sense. I did not pay attention to the categories.
          This is now understood

          Comment

          Working...
          X