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

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


From   "Clive Nicholas" <Clive.Nicholas@newcastle.ac.uk>
To   statalist@hsphsun2.harvard.edu
Subject   RE: st: RE: Nested If / then statement in a Bar Graph
Date   Wed, 25 Aug 2004 03:00:43 +0100 (BST)

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/



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