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

Re: st: Adding R-Squared to sw command output


From   Richard Williams <[email protected]>
To   [email protected]
Subject   Re: st: Adding R-Squared to sw command output
Date   Thu, 27 May 2004 10:17:20 -0500

At 03:53 PM 5/27/2004 +0100, Rena Jenkins wrote:
Is there a Stata programming guru out there who could help me modify the sw command so that the R-squared of the model is output at each stage? (I am just running a linear regression.) i.e. to print the value of e(r2) at each stage.

So that when you run something like
sw regress y x1 x2 x3, pe(0.05)

Instead of
begin with empty model
p = 0.0032 < 0.0500 adding x2
p = 0.0153 < 0.0500 adding x1
p = 0.0424 < 0.0500 adding x3

You get something like:
begin with empty model
p = 0.0032 < 0.0500 adding x2, R-squared = 0.2018
p = 0.0153 < 0.0500 adding x1, R-squared = 0.2523
p = 0.0424 < 0.0500 adding x3, R-squared = 0.2852
Rather than replacing sw.ado, I would suggest copying it as sw2.ado, and place it in c:\ado\personal. Change the line that says "program define sw" to "program define sw2". Then, search for the line that includes the word "adding". Replace it with

di in gr " < " %5.4f $HSW_Pe " adding " in ye "${HSW_`k1'}" in gr ", R^2 = " in ye e(r2)

This works with ols regression; sw2 would need further coding if you wanted to make it more general than that. I get output like

. sw2 reg income educ jobexp black, pe(.10)
begin with empty model
p = 0.0000 < 0.1000 adding educ, R^2 = .65926337
p = 0.0000 < 0.1000 adding jobexp, R^2 = .81626138
p = 0.0000 < 0.1000 adding black, R^2 = .82641678

If you really want blow by blow accounts of what is happening in a stepwise regression, SPSS is better.

-------------------------------------------
Richard Williams, Notre Dame Dept of Sociology
OFFICE: (574)631-6668, (574)631-6463
FAX: (574)288-4373
HOME: (574)289-5227
EMAIL: [email protected]
WWW (personal): http://www.nd.edu/~rwilliam
WWW (department): http://www.nd.edu/~soc

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