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

From |
"David Harrison" <David@icnarc.org> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: RE: Nested If / then statement in a Bar Graph |

Date |
Wed, 25 Aug 2004 09:47:46 +0100 |

To get the beta weights, you need to add the lines betacoef matrix A=r(beta) anywhere after the -regress- and before -foreach- (straight after -regress- seems the obvious place) and change the line gen `b_`v'' = _b[`v'] to gen `b_`v'' = A[1,`i'] Hope this helps, David david@icnarc.org -----Original Message----- From: Clive Nicholas [mailto:Clive.Nicholas@newcastle.ac.uk] Sent: 25 August 2004 03:01 To: statalist@hsphsun2.harvard.edu Subject: RE: st: RE: Nested If / then statement in a Bar Graph David Harrison wrote: > The other option if you want more variables is to produce your own wrapper > command for both -regress- and -graph bar-, such as: > > program define grreg > version 8 > syntax varlist(min=2 numeric) > regress `varlist' > qui { > tokenize `varlist' > macro shift > local vlist `*' > local blist "" > local bars "" > local i 0 > local rel "" > local tcrit=invttail(e(df_r),.025) > foreach v of local vlist { > local i=`i'+1 > tempvar b_`v' > gen `b_`v'' = _b[`v'] > scalar t_`v' = _b[`v'] / _se[`v'] > local blist "`blist' `b_`v''" > local rel `"`rel' `i' "`v'""' > if abs(t_`v') > `tcrit' { > local bars `"`bars' bar(`i', bcolor(red))"' > } > else { > local bars `"`bars' bar(`i', bcolor(blue))"' > } > } > graph bar (mean) `blist', bargap(30) `bars' /// > ytitle("Parameter Estimate") blabel(bar, position(outside)) /// > showyvars yvaroptions(relabel(`rel')) legend(off) > } > end > > The syntax would then be, e.g., -grreg price disp length- producing both > the regression and the graph in one go. > > Obviously there's lots of scope for more bells & whistles on this like > -if-, -in- and passing options through to both -regress- and -graph-. Thanks for this: this is also very good. I wanted to add Scott Merryman's suggested code from my earlier query: . betacoef . matrix A = r(beta) to this. However, I couldn't work out where this goes so that I could turn your -grreg- into a graphed regression with the beta weights. Alternatively, I added -beta- to the fourth line, but this made no difference to the outcome. CLIVE NICHOLAS |t: 0(044)191 222 5969 Politics |e: clive.nicholas@ncl.ac.uk Newcastle University |http://www.ncl.ac.uk/geps * * 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/ * * 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**:**RE: st: RE: Nested If / then statement in a Bar Graph***From:*"Clive Nicholas" <Clive.Nicholas@newcastle.ac.uk>

- Prev by Date:
**Re: st: xtnbreg and xtlogit** - Next by Date:
**Re: st: xtnbreg and xtlogit** - Previous by thread:
**Re: st: Automatic mean-centering?** - Next by thread:
**RE: st: RE: Nested If / then statement in a Bar Graph** - Index(es):

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