Announcement

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

  • Testing Statistical Significance of Difference in Proportions

    Hello, I'm trying to test differences in proportions by year, so I figured that I could use:

    collapse (sum) countTotalPatients countTotalMentalHealth countTotalSubstanceAbuse countTotalMedical, by(Year)
    bysort Year: gen ProportionMentalHealth = (countTotalMentalHealth/countTotalPatients)
    prtest PerMentalHealth, by(Year)

    However, that didn't work. Does anyone have any suggestions?


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int Year str2 State float(countTotalPatients countTotalMentalHealth countTotalSubstanceAbuse countTotalMedical)
    2020 "AK"   84124   9103  2448   74109
    2021 "AK"   91386   9531  1319   76509
    2022 "AK"   88262   9039  1854   74512
    2020 "AL"  191920  13142  4352  167658
    2021 "AL"  201003   8885  2276  169769
    2022 "AL"  191288  12463  3819  169143
    2020 "AR"  195413   9640  1265  186202
    2021 "AR"  208250  11474  1533  198479
    2022 "AR"  218372  10293  4300  205909
    2020 "AZ"  575336  99114  5963  511704
    2021 "AZ"  616050  97413  4355  546087
    2022 "AZ"  627570  97186  2721  545378
    2020 "CA" 3421151 254554 38707 3030039
    2021 "CA" 3547397 265081 39832 3121288
    2022 "CA" 3628056 272613 42046 3184629
    2020 "CO"  479782  77730  5684  436372
    2021 "CO"  474838  75550  6534  436168
    2022 "CO"  488467  75526  6120  443925
    2020 "CT"  244280  30834  2702  211276
    2021 "CT"  259808  30964  2429  224130
    2022 "CT"  265919  31348  2503  228160
    2020 "DC"  181626  16257  1535  164556
    2021 "DC"  183993  13302  1793  159784
    2022 "DC"  171836  17893  1979  151961
    2020 "DE"   17127   1476   991   13419
    2021 "DE"   18561   1906   423   16108
    2022 "DE"   16704   1334   386   14312
    2020 "FL"  856284  90077 11104  657220
    2021 "FL"  929544 140738  7593  686202
    2022 "FL"  947705 136804 15037  740644
    2020 "GA"  439725  18264  9525  409386
    2021 "GA"  468543  17434  7526  433203
    2022 "GA"  484750  20852  7363  440349
    2020 "HI"   84546   8969  1515   70616
    2021 "HI"   90000   9329  1341   75500
    2022 "HI"  111090   8755  1287   85495
    2020 "IA"  192156  20164  1139  155649
    2021 "IA"  194731  23143  1164  153569
    2022 "IA"  182259  20873  1165  139684
    2020 "ID"   98948  12089  1966   85612
    2021 "ID"  100983  11258  2062   82136
    2022 "ID"   99310  10142  1928   81216
    2020 "IL"  995147  89811 12113  922580
    2021 "IL" 1045582  91231 11331  973445
    2022 "IL"  997491  92113 13093  917098
    2020 "IN"  404851  44949  6583  362348
    2021 "IN"  444260  50195  6703  389482
    2022 "IN"  473159  55325  8080  416068
    2020 "KS"  142619  18499  1232  116292
    2021 "KS"  160706  21219  1164  136760
    2022 "KS"  170856  20619   910  146128
    2020 "KY"  354848  19663  2856  320763
    2021 "KY"  384265  21592  3832  346507
    2022 "KY"  392847  23934  4141  358048
    2020 "LA"  263438  50959  7036  211732
    2021 "LA"  278327  51413  6996  216547
    2022 "LA"  282797  58834  7566  209895
    2020 "MA"  610965  52511 12746  541574
    2021 "MA"  630019  53087 12799  560017
    2022 "MA"  637176  52021 10730  568499
    2020 "MD"  284521  20368  9783  260847
    2021 "MD"  314731  21752  4563  285388
    2022 "MD"  319088  23806  3148  286750
    2020 "ME"  155488  12774  3016  130452
    2021 "ME"  165043  12623  4287  137826
    2022 "ME"  170421  13513  4797  140703
    2020 "MI"  484422  54552  7630  379222
    2021 "MI"  504584  53230  7975  386859
    2022 "MI"  504498  53075  7914  390138
    2020 "MN"   82223   9809   766   55279
    2021 "MN"   88588   9634   711   57617
    2022 "MN"   85698   8939   656   58039
    2020 "MO"  438647  62779  4847  286788
    2021 "MO"  472188  68673  7954  300176
    2022 "MO"  479018  74885  9780  310526
    2020 "MS"  230580  11092  5056  208266
    2021 "MS"  242614  12605  5247  218965
    2022 "MS"  244174  13298  9121  217708
    2020 "MT"   68543   9305  1783   55211
    2021 "MT"   72687   9442  1973   59036
    2022 "MT"   77320   9719  1699   63692
    2020 "NC"  435359  42612  8901  363548
    2021 "NC"  444484  38334  6264  378088
    2022 "NC"  470943  39518  6075  409851
    2020 "ND"   14415    709   392   10608
    2021 "ND"   15786    820   324   10797
    2022 "ND"   14864   1002   569   11268
    2020 "NE"   78157   8093   681   65807
    2021 "NE"   79051   9991   900   65079
    2022 "NE"   79691  10250   774   64940
    2020 "NH"   76124   9183  1802   69031
    2021 "NH"   79758   9490  3085   72800
    2022 "NH"   80775  10097  2044   73265
    2020 "NJ"  355817  22124  2656  319948
    2021 "NJ"  393969  23888  2427  347241
    2022 "NJ"  373111  22490  1999  323570
    2020 "NM"  265671  42329  3702  213001
    2021 "NM"  279783  39633  6267  225140
    2022 "NM"  279687  41753  3694  217741
    2020 "NV"   45445   7202  1158   38949
    end

  • #2
    If you want to use prtest on the total annual, you don't need to collapse. (You could collapse and get the same numbers).

    Code:
    tabstat countTotalMentalHealth countTotalPatients, by(Year) stats(sum) save
    forv i = 1/3 {
        local m`i' = r(Stat`i')[1,1]/r(Stat`i')[1,2]
        local n`i' = r(Stat`i')[1,2]
    }
    
    prtesti `n1' `m1'   `n2' `m2'
    prtesti `n1' `m1'   `n3' `m3'
    prtesti `n2' `m2'   `n3' `m3'

    Comment


    • #3
      Thank You! It worked!

      Comment


      • #4
        The differences are tiny. The large sample sizes are driving the results. Lots of power.

        Comment


        • #5
          I figured that I didn't need to test the difference, but if I wanted to do a McNemar's test would I have to expand the data and somehow get binary observations?

          Comment

          Working...
          X