I would like to use an F-Test for Equality of Variances on a variable to compare two groups. Normally, this would be done with an `sdtest`

command in Stata or a `var.test`

command in R. However, the data come from a multi-stage, stratified random sample with disproportionate selection, and thus, need to be weighted.

Both Stata and R have packages geared at running analyses with complex sampling weights. In Stata it is done via the `svyset`

command and subsequent analyses are ran with the `svy`

prefix (e.g. `svy: mean`

). Likewise, it is done in R via the `survey`

package, which also subsequently conducts analyses with a `svy`

prefix (e.g. `svymean`

).

But, unless I have overlooked something, neither seem able to do an F-test for Equality of Variances (or a similar test) on weighted data. They both can do difference in means t-tests (R via `svyttest`

) and Stata via postestimation commands.

Is there a workaround for this? A different test, perhaps, or a manual override in which the weighted data are converted to appear unweighted? Or is it statistically dubious to test for the equality of variances between two groups using weighted data (given that weighting affects variances), and therefore the reason why such options do not exist in Stata or R? If that's the case, what should one do when he or she wants to compare the variances of two groups that were sampled disproportionately? Certainly running F-tests on unweighted data isn't a better option, and since many surveys feature disproportionate selection methods, there must be some viable solution other than simply saying "you can't do that", right?

**Contents**hide

#### Best Answer

You can compare variances from first principles, i.e., by calculating the variance as the difference between value-squared and mean-squared.

`webuse nhanes2, clear gen bpsystol_sq = bpsystol* bpsystol svy : mean bpsystol*, over( female ) * estimated variance in group 0 nlcom ( _b[bpsystol_sq:0] - _b[bpsystol:0]*_b[bpsystol:0]) * estimated variance in group 1 nlcom ( _b[bpsystol_sq:1] - _b[bpsystol:1]*_b[bpsystol:1]) * equality test testnl ( _b[bpsystol_sq:1] - _b[bpsystol:1]*_b[bpsystol:1]) /// = ( _b[bpsystol_sq:0] - _b[bpsystol:0]*_b[bpsystol:0]) `

### Similar Posts:

- Solved – Equality of variances based on Rule of Thumb (for very small groups)
- Solved – standardize the data to calculate variance
- Solved – Whether to use nonparametric tests to compare two groups when sample size is large but assumptions are violated
- Solved – Do you use a chi-squared test or a t-test for equality of variances
- Solved – How to interpret the results from the F-test in excel