Announcement

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

  • Test of Variances between Groups and across Countries

    Essentially the problem is this:

    I have a variable of interest "X" and data on the values of "X" for a set of countries and years. Further, I have created an indicator variable "I" that defines each year (uniquely for each country, i.e. the indicator will not have the same value in 1969 for all countries) as part of group 1 or group 2 according to the value of another variable Y.

    Now what I want to check is whether the variable X has different variance during years in group 1 versus years in group 2. I have thought of two ways of doing this

    1st: A regular sdtest
    Code:
    sdtest X, by(I)
    2nd: Collapsing the sd by country and I and performing a t-test
    Code:
    collapse(sd) X, by(I country)
    ttest X, by(I)
    Both of these tests give outputs, but I do not believe they capture what I really want, or what would statistically informative. The issue is that both tests seem to pool the countries together before testing for difference in variances, which means that differences between countries aren't really being accounted for.

    Obviously I could just perform this test individually for each country, but the idea is (especially since I have many more variables than X that I could test) that I would have some sort of pooled result. How do I control for the difference between countries in this sort of test? Is there a way to perform a test for difference in variances for each country and then pool them? I have tried looking around but I have not seen much information on this sort of issue, so any help would be appreciated.

  • #2
    Anthony:
    I'm not sure I got what you are after.
    That said, you may want to consider -oneway-, which outcome reports a test of equality of variances between groups:
    Code:
    . use "https://www.stata-press.com/data/r16/nlswork.dta"
    (National Longitudinal Survey.  Young Women 14-26 years of age in 1968)
    
    . bysort year: oneway oneway age msp , bonferroni
    
    ---------------------------------------------------------------------------------------------------------------------------------------
    -> year = 68
    variable oneway not found
    r(111);
    
    . bysort year: oneway age msp , bonferroni
    
    ---------------------------------------------------------------------------------------------------------------------------------------
    -> year = 68
    
                            Analysis of Variance
        Source              SS         df      MS            F     Prob > F
    ------------------------------------------------------------------------
    Between groups      454.848424      1   454.848424    107.06     0.0000
     Within groups      5833.19085   1373   4.24850025
    ------------------------------------------------------------------------
        Total           6288.03927   1374    4.5764478
    
    Bartlett's test for equal variances:  chi2(1) =   2.3944  Prob>chi2 = 0.122
    
          Comparison of age in current year by 1 if married, spouse present
                                    (Bonferroni)
    Row Mean-|
    Col Mean |          0
    ---------+-----------
           1 |    1.15367
             |      0.000
    
    ---------------------------------------------------------------------------------------------------------------------------------------
    -> year = 69
    
                            Analysis of Variance
        Source              SS         df      MS            F     Prob > F
    ------------------------------------------------------------------------
    Between groups      607.270537      1   607.270537    128.22     0.0000
     Within groups      5782.64116   1221   4.73598784
    ------------------------------------------------------------------------
        Total           6389.91169   1222    5.2290603
    
    Bartlett's test for equal variances:  chi2(1) =   1.0927  Prob>chi2 = 0.296
    
          Comparison of age in current year by 1 if married, spouse present
                                    (Bonferroni)
    Row Mean-|
    Col Mean |          0
    ---------+-----------
           1 |    1.41242
             |      0.000
    
    ---------------------------------------------------------------------------------------------------------------------------------------
    -> year = 70
    
                            Analysis of Variance
        Source              SS         df      MS            F     Prob > F
    ------------------------------------------------------------------------
    Between groups      788.267919      1   788.267919    129.73     0.0000
     Within groups      10232.1283   1684   6.07608568
    ------------------------------------------------------------------------
        Total           11020.3962   1685   6.54029448
    
    Bartlett's test for equal variances:  chi2(1) =   0.1038  Prob>chi2 = 0.747
    
          Comparison of age in current year by 1 if married, spouse present
                                    (Bonferroni)
    Row Mean-|
    Col Mean |          0
    ---------+-----------
           1 |    1.36976
             |      0.000
    
    ---------------------------------------------------------------------------------------------------------------------------------------
    -> year = 71
    
                            Analysis of Variance
        Source              SS         df      MS            F     Prob > F
    ------------------------------------------------------------------------
    Between groups      1052.48981      1   1052.48981    149.50     0.0000
     Within groups      13017.0283   1849   7.04003693
    ------------------------------------------------------------------------
        Total           14069.5181   1850   7.60514492
    
    Bartlett's test for equal variances:  chi2(1) =   6.3116  Prob>chi2 = 0.012
    
          Comparison of age in current year by 1 if married, spouse present
                                    (Bonferroni)
    Row Mean-|
    Col Mean |          0
    ---------+-----------
           1 |    1.51691
             |      0.000
    
    ---------------------------------------------------------------------------------------------------------------------------------------
    -> year = 72
    
                            Analysis of Variance
        Source              SS         df      MS            F     Prob > F
    ------------------------------------------------------------------------
    Between groups      854.179207      1   854.179207    103.15     0.0000
     Within groups      14002.6879   1691   8.28071431
    ------------------------------------------------------------------------
        Total           14856.8671   1692   8.78065431
    
    Bartlett's test for equal variances:  chi2(1) =   6.2975  Prob>chi2 = 0.012
    
          Comparison of age in current year by 1 if married, spouse present
                                    (Bonferroni)
    Row Mean-|
    Col Mean |          0
    ---------+-----------
           1 |    1.42994
             |      0.000
    
    ---------------------------------------------------------------------------------------------------------------------------------------
    -> year = 73
    
                            Analysis of Variance
        Source              SS         df      MS            F     Prob > F
    ------------------------------------------------------------------------
    Between groups      644.351069      1   644.351069     76.17     0.0000
     Within groups      16741.4541   1979   8.45955234
    ------------------------------------------------------------------------
        Total           17385.8051   1980   8.78070967
    
    Bartlett's test for equal variances:  chi2(1) =   0.0191  Prob>chi2 = 0.890
    
          Comparison of age in current year by 1 if married, spouse present
                                    (Bonferroni)
    Row Mean-|
    Col Mean |          0
    ---------+-----------
           1 |    1.16704
             |      0.000
    
    ---------------------------------------------------------------------------------------------------------------------------------------
    -> year = 75
    
                            Analysis of Variance
        Source              SS         df      MS            F     Prob > F
    ------------------------------------------------------------------------
    Between groups      311.809781      1   311.809781     34.89     0.0000
     Within groups      19118.0239   2139    8.9378326
    ------------------------------------------------------------------------
        Total           19429.8337   2140   9.07936155
    
    Bartlett's test for equal variances:  chi2(1) =   0.2328  Prob>chi2 = 0.629
    
          Comparison of age in current year by 1 if married, spouse present
                                    (Bonferroni)
    Row Mean-|
    Col Mean |          0
    ---------+-----------
           1 |    .790469
             |      0.000
    
    ---------------------------------------------------------------------------------------------------------------------------------------
    -> year = 77
    
                            Analysis of Variance
        Source              SS         df      MS            F     Prob > F
    ------------------------------------------------------------------------
    Between groups      257.836219      1   257.836219     27.66     0.0000
     Within groups       20174.493   2164   9.32277863
    ------------------------------------------------------------------------
        Total           20432.3292   2165   9.43756544
    
    Bartlett's test for equal variances:  chi2(1) =   0.1076  Prob>chi2 = 0.743
    
          Comparison of age in current year by 1 if married, spouse present
                                    (Bonferroni)
    Row Mean-|
    Col Mean |          0
    ---------+-----------
           1 |    .721431
             |      0.000
    
    ---------------------------------------------------------------------------------------------------------------------------------------
    -> year = 78
    
                            Analysis of Variance
        Source              SS         df      MS            F     Prob > F
    ------------------------------------------------------------------------
    Between groups      199.429364      1   199.429364     20.92     0.0000
     Within groups      18597.5087   1951   9.53229558
    ------------------------------------------------------------------------
        Total            18796.938   1952   9.62957892
    
    Bartlett's test for equal variances:  chi2(1) =   0.6871  Prob>chi2 = 0.407
    
          Comparison of age in current year by 1 if married, spouse present
                                    (Bonferroni)
    Row Mean-|
    Col Mean |          0
    ---------+-----------
           1 |    .665546
             |      0.000
    
    ---------------------------------------------------------------------------------------------------------------------------------------
    -> year = 80
    
                            Analysis of Variance
        Source              SS         df      MS            F     Prob > F
    ------------------------------------------------------------------------
    Between groups      63.0576925      1   63.0576925      6.72     0.0096
     Within groups      17304.1053   1845   9.37891885
    ------------------------------------------------------------------------
        Total            17367.163   1846   9.40799727
    
    Bartlett's test for equal variances:  chi2(1) =   0.0083  Prob>chi2 = 0.927
    
          Comparison of age in current year by 1 if married, spouse present
                                    (Bonferroni)
    Row Mean-|
    Col Mean |          0
    ---------+-----------
           1 |    .382635
             |      0.010
    
    ---------------------------------------------------------------------------------------------------------------------------------------
    -> year = 82
    
                            Analysis of Variance
        Source              SS         df      MS            F     Prob > F
    ------------------------------------------------------------------------
    Between groups      4.30990478      1   4.30990478      0.45     0.5014
     Within groups      19859.5491   2083   9.53410902
    ------------------------------------------------------------------------
        Total            19863.859   2084    9.5316022
    
    Bartlett's test for equal variances:  chi2(1) =   0.0016  Prob>chi2 = 0.968
    
          Comparison of age in current year by 1 if married, spouse present
                                    (Bonferroni)
    Row Mean-|
    Col Mean |          0
    ---------+-----------
           1 |    .094545
             |      0.501
    
    ---------------------------------------------------------------------------------------------------------------------------------------
    -> year = 83
    
                            Analysis of Variance
        Source              SS         df      MS            F     Prob > F
    ------------------------------------------------------------------------
    Between groups      2.23017691      1   2.23017691      0.23     0.6304
     Within groups      19116.9143   1985   9.63068729
    ------------------------------------------------------------------------
        Total           19119.1444   1986   9.62696095
    
    Bartlett's test for equal variances:  chi2(1) =   0.0166  Prob>chi2 = 0.898
    
          Comparison of age in current year by 1 if married, spouse present
                                    (Bonferroni)
    Row Mean-|
    Col Mean |          0
    ---------+-----------
           1 |   -.069241
             |      0.630
    
    ---------------------------------------------------------------------------------------------------------------------------------------
    -> year = 85
    
                            Analysis of Variance
        Source              SS         df      MS            F     Prob > F
    ------------------------------------------------------------------------
    Between groups       15.198101      1    15.198101      1.61     0.2050
     Within groups       19683.859   2082   9.45430307
    ------------------------------------------------------------------------
        Total           19699.0571   2083   9.45706054
    
    Bartlett's test for equal variances:  chi2(1) =   0.0488  Prob>chi2 = 0.825
    
          Comparison of age in current year by 1 if married, spouse present
                                    (Bonferroni)
    Row Mean-|
    Col Mean |          0
    ---------+-----------
           1 |   -.177872
             |      0.205
    
    ---------------------------------------------------------------------------------------------------------------------------------------
    -> year = 87
    
                            Analysis of Variance
        Source              SS         df      MS            F     Prob > F
    ------------------------------------------------------------------------
    Between groups      1.57847073      1   1.57847073      0.16     0.6851
     Within groups      20753.1068   2162   9.59903184
    ------------------------------------------------------------------------
        Total           20754.6853   2163   9.59532377
    
    Bartlett's test for equal variances:  chi2(1) =   0.2026  Prob>chi2 = 0.653
    
          Comparison of age in current year by 1 if married, spouse present
                                    (Bonferroni)
    Row Mean-|
    Col Mean |          0
    ---------+-----------
           1 |   -.056445
             |      0.685
    
    ---------------------------------------------------------------------------------------------------------------------------------------
    -> year = 88
    
                            Analysis of Variance
        Source              SS         df      MS            F     Prob > F
    ------------------------------------------------------------------------
    Between groups      5.17311363      1   5.17311363      0.55     0.4578
     Within groups      21167.1936   2256   9.38262127
    ------------------------------------------------------------------------
        Total           21172.3667   2257   9.38075618
    
    Bartlett's test for equal variances:  chi2(1) =   0.0291  Prob>chi2 = 0.865
    
          Comparison of age in current year by 1 if married, spouse present
                                    (Bonferroni)
    Row Mean-|
    Col Mean |          0
    ---------+-----------
           1 |   -.099905
             |      0.458
    
    
    .
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment

    Working...
    X