Error Bar Plots Stata
Contents |
bars? Say that you were looking at writing scores broken down by race and ses. You might want to graph the mean and confidence interval for each group stata bar graph with error bars using a bar chart with error bars as illustrated below. This FAQ shows how scatter plots in stata you can make a graph like this, building it up step by step. First, lets get the data file we will be
Standard Error Stata
using. use http://www.ats.ucla.edu/stat/stata/notes/hsb2, clear Now, let's use the collapse command to make the mean and standard deviation by race and ses. collapse (mean) meanwrite= write (sd) sdwrite=write (count) n=write, by(race ses) Now, let's make the
Standard Deviation Stata
upper and lower values of the confidence interval. generate hiwrite = meanwrite + invttail(n-1,0.025)*(sdwrite / sqrt(n)) generate lowrite = meanwrite - invttail(n-1,0.025)*(sdwrite / sqrt(n)) Now we are ready to make a bar graph of the data The graph bar command makes a pretty good bar graph. graph bar meanwrite, over(race) over(ses) We can make the graph look a bit prettier by adding the asyvars option as shown below. graph bar variance stata meanwrite, over(race) over(ses) asyvars But, this graph does not have the error bars in it. Unfortunately, as nice as the graph bar command is, it does not permit error bars. However, we can make a twoway graph that has error bars as shown below. Unfortunately, this graph is not as attractive as the graph from graph bar. graph twoway (bar meanwrite race) (rcap hiwrite lowrite race), by(ses) So, we have a conundrum. The graph bar command will make a lovely bar graph, but will not support error bars. The twoway bar command makes lovely error bars, but it does not resemble the nice graph that we liked from the graph bar command. However, we can finesse the twoway bar command to make a graph that resembles the graph bar command and then combine that with error bars. Here is a step by step process.First, we will make a variable sesrace that will be a single variable that contains the ses and race information. Note how sesrace has a gap between the levels of ses (at 5 and 10). generate sesrace = race if ses == 1 replace sesrace = race+5 if ses == 2 replace sesrace = race+10 if ses == 3 sort sesrace list sesrace ses race, sepby(ses) +----------------------
30 Jun 2003 14:43:13 +0100 Stephen McKay > I'm no expert but isn't > > twoway bar mean xcatvar || rcap upper lower xcatvar > > most of what you
Normal Distribution Stata
need? Overlaying a bar plot with capped spikes. > Stephen is quite correct. mean stata As I pointed out in a previous thread earlier in the month started by Buzz Burhans: > It so z score stata happens that Stata's been a bit laggard on producing > wrapper commands for plots showing error bars. > I doubt there's any policy there. > However, having implemented various high- > http://www.ats.ucla.edu/stat/stata/faq/barcap.htm level commands in one way does inhibit twisting > them in a different direction. -graph bar- > for example is basically built around a -collapse- > of the data. Building something else major on top of > that, such as machinery for adding confidence > intervals generally, would be, I guess, rather tricky. My posting then focused on my criticisms of a certain http://www.stata.com/statalist/archive/2003-06/msg00631.html kind of error bar plot, and Buzz's reply focused on his reaction to that critique. I don't think either of us convinced the other. However, what is said above for -graph bar- does not inhibit building something based on -graph twoway bar-, and you can try your own wrapper command. Here is a "no holds barred" (no bars held?) plot, error bars on top of thicker bars. You have to supply 1. bar height variable 2. upper error bar position variable 3. lower error bar position variable 4. other axis variable *! NJC 1.0.0 30jun2003 program baronbar version 8 syntax varlist(min=4 max=4) [if] [in] [, /// HORizontal VERTical base(str) BARWidth(str) /// BSTYle(str) BColor(str) BFColor(str) /// BLSTYle(str) BLColor(str) BLWidth(str) /// BLPattern(str) plot(str asis) * /// ] tokenize `varlist' args height upper lower groupvar local yttl : var label `height' if `"`yttl'"' == "" local yttl `height' if `"`plot'"' == "" local legend legend(nodraw) foreach o in /// base barwidth bstyle bcolor bfcolor /// blstyle blcolor blwidth blpattern { if `"``o''"' != "" local baropts "`baropts' `o'(``o'')" } graph twoway /// (bar `height' `groupvar' /// `if' `in', /// ytitle(`"`yttl'"')
errors Date Wed, 30 Mar 2005 15:08:40 +0100 In addition, these plots have _often_ been discussed on Statalist and various non-official solutions http://www.stata.com/statalist/archive/2005-03/msg00927.html touted. Searching on "detonator plots" will give one way in without too many false positives. Nick n.j.cox@durham.ac.uk Michael Blasnik > -help standard error bar - > > points you directly to serrbar as well as the ucla web site. > I don't think > that your effort qualifies as looking thoroughly, so I guess error bar > we can blame > you ;) Sascha Robert > > This time I really can't blame me for not having looked > thoroughly for a > > solution, I consulted both STATA help (graph bar) and "A > Visual Guide to > > Stata Graphics" by M. Mitchell... > > > > Is there error bar plots a way to display standard errors in bar plots (e.g. with > > something like 'twoway rcap hi low y_var')? > > Here's a lousy sketch of what I mean: > > > > - <-- (mean + se) > > | > > ---|--- <-- (mean) > > | | | > > | - | <-- (mean - se) > > | | * * 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: Re: Bar plots with standard errors From: Roger Newson
be down. Please try the request again. Your cache administrator is webmaster. Generated Mon, 10 Oct 2016 13:47:59 GMT by s_ac15 (squid/3.5.20)