Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Standard error of a ratio of two random variables


From   "Sergiy Radyakin" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: Standard error of a ratio of two random variables
Date   Mon, 12 Jan 2009 17:02:11 -0500

Dear All,

   I need to find a standard error of Z a ratio of two random
variables X and Y: Z=X/Y, where the means and SEs for X and Y are
known, as well as their corr coefficient. (In my particular case X and
Y are numbers of people that have such and such characteristics). I am
using delta-method according to [
http://www.math.umt.edu/patterson/549/Delta.pdf ] (see page 2(38)). I
then use svy:ratio to check my results and they don't match.  I wonder
if I am doing something wrong, or is it any kind of precision-related
problem (the difference is about 7%, i.e. 1.7959 vs. 1.6795), or is my
check simply wrong and not applicable in this case.

   I would appreciate if someone could look into the code and let me
know why the results are different.

Thank you,
    Sergiy Radyakin

Below is a do file that one can Ctrl+C/Ctrl+V to Stata's command line:

**** BEGIN OF RV_RATIO.DO ****
sysuse auto, clear
generate byte www=1
svyset [pw=www]

capture program drop st_error_of_ratio
program define  st_error_of_ratio, rclass
	syntax varlist(min=2 max=2)
	svy: mean `varlist'
	matrix B=e(b)
	local mux=B[1,1]
	local muy=B[1,2]
	matrix V=e(V)
	local sigma2x=V[1,1]
	local sigma2y=V[2,2]
	local sigmax_sigmay=V[1,2]
             svyset
	corr `varlist' [aw`=r(wexp)']
	local rho=r(rho)
	return scalar se = sqrt((`mux')^2*`sigma2y'/(`muy')^4 +
`sigma2x'/(`muy')^2 - 2*`mux'/(`muy')^3*`rho'*`sigmax_sigmay')
end
	st_error_of_ratio price length
             display as text "Estimated SE=" as result r(se)
	svy: ratio price / length
**** END OF RV_RATIO.DO ****
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index