This simple simulation-study shows the unbiasedness of the Sample Variance through a Monte-Carlo simulation in STATA.
This simulation is conducted using STATA since its programming capabilities facilitate the generation of multiple datasets and iterative analyses.
Monte-Carlo methods are numerical techniques relying on random sampling to approximate results. This work performs a Monte-Carlo simulation in order to examine whether the sample variance is an unbiased estimator for the population variance.
gen x = runiform()
Firstly, we generate a fixed number of independent repetitions of the rv X with a fixed amount of observations each. Consequently, we replace those repetitions with their sample variances.
clear
local N = 5000
local rep = 100
matrix stats = J(`rep', 1, .)
forv i = 1/`rep' {
clear
qui set obs `N'
gen x = runiform()
qui sum x
matrix stats[`i', 1] = r(sd)
}
clear
qui set obs `rep'
svmat stats, n(sd)
gen sample_var = sd1^2
drop sd1
Thus, we expect each sample variance to be approximately equal to
local var_unif = 1/12
ttest sample_var == `var_unif'