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

From |
"David Harrison" <[email protected]> |

To |
<[email protected]> |

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

Date |
Tue, 24 Aug 2004 14:23:02 +0100 |

```
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-.
David
[email protected]
-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: 24 August 2004 13:06
To: [email protected]
Subject: Re: st: RE: Nested If / then statement in a Bar Graph
----- Original Message -----
From: Clive Nicholas <[email protected]>
Date: Monday, August 23, 2004 10:43 pm
Subject: Re: st: RE: Nested If / then statement in a Bar Graph
<snip>
>
> This is pretty neat, Scott, but what if you want to change this to
> showthe graph as, say, thin(ish) horizontal bars? I changed -bar-
> to -hbar-
> everywhere in the code, but it threw up error messages, so
> obviously I was
> doing something wrong! That said, I was able to add extra bars for
> extravariables without too much difficulty.
>
Clive,
Changing -graph bar ... - to -graph hbar...- seems to work for me. One way to get thinner(ish) bars would be to change to gaps. Something like
graph hbar (mean) b_* , outergap(100) bargap(250) ///
> That leads to the second question. If you're like me and you're
> running a
> model with 50 variables, presumably there's no quick-and-dirty
> workaround.
Sometimes, tables can be nice.
I suppose, you could pick up the list of variables from -regress- and cycle through them in a more automated manner or pick up the elements you need from e(b) and e(V).
> Third, what if Alex wanted to use beta-weights as opposed to b-scores?
> Unfortunately, -ereturn list- doesn't leave these behind even if
> you enter
>
> . reg price disp length, beta
>
> but, again, maybe there's a workaround here, too.
Kit Baum's -betacoef- returns the beta coefficients in matrix. One way would be:
sysuse auto,clear
qui {
reg price disp length
betacoef
matrix A = r(beta)
gen b_disp = A[1,1]
gen b_length = A[1,2]
scalar t_disp = _b[disp] / _se[disp]
scalar t_length = _b[length] / _se[length]
if abs(t_disp) > 1.96 {
local bar1 "1, bfcolor(red) blcolor(red)"
}
else {
local bar1 "1, bfcolor(blue) blcolor(blue)"
}
if abs(t_length) > 1.96 {
local bar2 "2, bfcolor(red) blcolor(red)"
}
else {
local bar2 "2, bfcolor(blue) blcolor(blue)"
}
}
graph hbar (mean) b_* , outergap(100) bargap(250) ///
bar(`bar1') bar(`bar2') ytitle("Beta Coefficients") ///
blabel(bar, position(outside))
Scott
*
* 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**:**st: Automatic mean-centering?***From:*"Clive Nicholas" <[email protected]>

**RE: st: RE: Nested If / then statement in a Bar Graph***From:*"Clive Nicholas" <[email protected]>

- Prev by Date:
**Re: st: Questions** - Next by Date:
**st: vecstable graph ?** - Previous by thread:
**st: Happy Birthday** - Next by thread:
**RE: st: RE: Nested If / then statement in a Bar Graph** - Index(es):

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