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'
![STATA-output](https://private-user-images.githubusercontent.com/106596623/239692351-13842cc4-cb69-4ffc-b91c-8b5cc0bd487e.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0OTE3NzUsIm5iZiI6MTczOTQ5MTQ3NSwicGF0aCI6Ii8xMDY1OTY2MjMvMjM5NjkyMzUxLTEzODQyY2M0LWNiNjktNGZmYy1iOTFjLThiNWNjMGJkNDg3ZS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjE0JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxNFQwMDA0MzVaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0wZDZjZTQyYzUxYzZmNDYxNTAwNjgwODBmNWQ5MDI5M2YzOWUwOWFiNzhlMDVjN2ExNjg2ZDEyZGFlN2FlY2Q1JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.ZdPq21baajPYVOfxVvOB1DRVI_DOK1EQ66T1SxByqdI)