Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Simulating Heteroscedasticity and correcting it


From   Tirthankar Chakravarty <[email protected]>
To   [email protected]
Subject   Re: st: Simulating Heteroscedasticity and correcting it
Date   Wed, 6 Jun 2012 11:46:18 -0700

The following code should be self-explanatory. You need to weight the
constant as well.

*----------------------------------------------------------------------------------
clear*
program wls_sim, eclass
	drop _all
	set obs 10000
	
	gen x1 = rnormal()
	gen x2 = rnormal()
	
	gen e =  rnormal()
	
	* conditional heteroskedasticity
	gen s = exp(0.4*x1)
	gen e_het= s*e
	
	* outcome variable
	gen y_het=10 +3*x1 + 2*x2 +e_het
	
	* OLS
	reg y_het x1 x2
	
	* WLS
	g ones = 1
	g known_ones = ones/s

	gen known_y=y/s
	gen known_x1=x1/s
	gen known_x2=x2/s
	
	reg known_y known_ones known_x1 known_x2, nocons
	matrix vCoeff = e(b)
	ereturn repost b = vCoeff
end

simulate _b, reps(100): wls_sim
su
*----------------------------------------------------------------------------------

T

On Wed, Jun 6, 2012 at 3:33 AM, Veit Böckers
<[email protected]> wrote:
> Hello,
>
>
>
>
>
> I really hope you can help me out on this. I  want to simulate
> heteroscedasticity and then correct  under the two regimes  a) known
> heteroscedasticity factor  b) unknown heteroscedasticity factor (i.e.
> white-robust). My question concerns the correction of heteroscedasticity if
>  the factor causing the heteroscedasticity, Omega, is known. Omega is
> defined as:
>
>  Var(Residual)=sigma^2*Omega  ; Omega= diag[(lambda_1)^2; (lambda_2)^2;
> (lambda_3)^2… (lambda_t)^2]
>
>
>
> If I recall correctly, my regression can be corrected like this :  y/lambda
> = constant+ beta* x/lambda + residual/lambda. However, I seem to have made a
> mistake that I cannot find. Here is my do-file:
>
>
>
> set obs 1000
>
> gen x1 = 2 * invnorm(uniform())
>
> gen x2 = 4 * invnorm(uniform())
>
>
>
> *** Generate Residual
>
> gen e =  2*invnorm(uniform())
>
> sum e
>
> replace e = e-r(mean)
>
>
>
> *Generate Heteroscedasticity with factor “s”  influencing my residual “e”
>
> gen s = exp(0.4*x1)
>
> gen e_het= s*e
>
>
>
> *Generate true y under heteroscedasticity
>
> gen y_het=10 +3*x1 + 2*x2 +e_het
>
>
>
> * Estimation under total disregard of heteroscedasticity
>
> reg y_het x1 x2
>
>
>
> *** Estimation under the “known heteroscedasticity factor” regime
>
>
>
> gen known_y=y/s
>
> gen known_x1=x1/s
>
> gen known_x2=x2/s
>
>
>
>
>
> reg known_y known_x1 known_x2
>
>
>
> ---
>
> Why do I not get close to the true relationship of y and x1/x2?
>
>
>
> Thank you very much in advance for your answers,
>
>
>
> Veit
>
>



-- 
Tirthankar Chakravarty
[email protected]
[email protected]

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index