Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: marginal effects of interacting variables


From   "Scott Merryman" <[email protected]>
To   <[email protected]>
Subject   st: Re: marginal effects of interacting variables
Date   Fri, 3 Oct 2003 23:46:41 -0500

----- Original Message ----- 
From: "Mehmet Beceren" <[email protected]>
To: <[email protected]>
Sent: Friday, October 03, 2003 9:19 AM
Subject: st: marginal effects of interacting variables


> Hi,
> I have a regression with interacting variables in the following form: Y = a
> + bX1 + cX2 + zX1X2
> And I would like to estimate the total marginal effect (total derivative)
> of X1 and the standard error of the total derivative.
> The derivative at the mean of the variables will be b + z* meanX1*meanX2
>
> Does anyone know a quick command to get the SE of the total derivative
> after such a regression? Manual calculations become harder as the number of
> interacting variables increase.
>
> Mehmet
>

Would not the marginal effect of X1 be: b + z*X2 (where X2 could be the sample
mean)

The variance would be: var[b] + X2^2*var[z] + 2*X2*cov[b,z] (see Greene, 4th ed.
page 326.)

below is a very simple program to calculate the marginal effects and the
variance of interaction terms.

Hope this helps,
Scott


program marginalx, rclass
version 8.1
syntax , x(varname) y(varname) xy(varname)

sum `y' if e(sample), meanonly

local marginal = _b[`x'] + _b[`xy']*r(mean)

matrix A = e(V)
matrix B1 = A["`x'" , "`x'"]
local var_b1 = B1[1,1]

matrix B2 = A["`xy'" , "`xy'"]
local var_b2 = B2[1,1]

matrix B3 = A["`x'" , "`xy'"]
local covar_b1b2 = B3[1,1]

local variance = `var_b1' + (r(mean)^2)*`var_b2' + 2*r(mean)*`covar_b1b2'

dis ""
disp in gr "Marginal effect of `x' at the mean of `y' = " `marginal'
disp in gr  "Variance of marginal effect of `x' at the mean of `y' = "
`variance'

return scalar margx = `marginal'
return scalar var_margx = `variance'

end


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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