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
[email protected]
-----Original Message-----
From: Clive Nicholas [mailto:[email protected]]
Sent: 25 August 2004 03:01
To: [email protected]
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: [email protected]
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/