[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
Chip Hunter <Lhunter@bus.wisc.edu> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
st: interactions, slopes, and standard errors |

Date |
Fri, 26 Mar 2004 12:13:20 -0600 |

Has anyone written a general program to calculate and display the estimated slope and associated error of Y on x1 at various values of x2, where Y = b0 + b1x1 + b2x2 + b3x1x2

Last fall Scott Merryman posted a nice program (which I copy in, below) which takes care of this at the mean of x2. Thanks, Scott!, We could also be interested in doing it for other values.

Chip Hunter

**

- Scott Merryman's program to calculate the marginal effects and the variance of interaction terms -

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

**************************************************

Chip Hunter

University of Wisconsin-Madison

School of Business

Management and Human Resources Dept.

4114 Grainger Hall

975 University Ave.

Madison, WI 53706

608-265-3533

**************************************************

*

* 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/

**Follow-Ups**:**st: Re: interactions, slopes, and standard errors***From:*"Scott Merryman" <smerryman@kc.rr.com>

**Re: st: interactions, slopes, and standard errors***From:*"Jesper B. Sorensen" <sorensen@mit.edu>

- Prev by Date:
**RE: A simpler count question Re: st: RE: Re: Counts of different values in one variable by another variable** - Next by Date:
**st: IVREG2** - Previous by thread:
**RE: A simpler count question Re: st: RE: Re: Counts of different values in one variable by another variable** - Next by thread:
**Re: st: interactions, slopes, and standard errors** - Index(es):

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