Transcription of Syntax - Stata
1 Bar Bar chartsSyntaxMenuDescriptionOptionsRemark s and examplesReferencesAlso seeSyntaxgraph baryvars[if] [in] [weight] [,options]graph hbaryvars[if] [in] [weight] [,options]whereyvarsis(asis)varlistor is(percent)[varlist]|(count)[varlist]or is[(stat)]varname[[(stat)]..][(stat)]var list[[(stat)]..][(stat)] [name=]varname[..] [[(stat)]..]wherestatmay be any ofmean median p1 p2..p99 sum count percent min maxorany of the otherstatsdefined in [D]collapseyvarsis optional if the optionover(varname)is the default statistic, andpercentages are calculated the default whenvarnameorvarlistis specified andstatis not thefirst percentile,p2means the second percentile, and so on;p50means the same the number of nonmissing values of the specified over which bars are drawnyvaroptionsvariables that are the barslookofbaroptionshow the bars looklegendingoptionshowyvarsare labeledaxisoptionshow the numericalyaxis is labeledtitleandotheroptionstitles, added text, aspect ratio, is defined bar Bar chartsgroupoptionsDescriptionover(varnam e[,oversubopts])categories.
2 Option may be repeatednofillomit empty categoriesmissingkeep missing value as categoryallcategoriesinclude all categories in the datasetyvaroptionsDescriptionascategoryt reatyvarsas firstover()groupasyvarstreat firstover()group asyvarspercentagesshow percentages withinyvarsstackstack theyvarbarscwcalculateyvarstatistics omitting missing values of anyyvarlookofbaroptionsDescriptionouterg ap([*]#)gap between edge and first bar and between last bar and edgebargap(#)gap betweenyvarbars; default is 0intensity([*]#)intensity of filllintensity([*]#)intensity of outlinepcycle(#)bar styles before pstyles recyclebar(#,barlookoptions)look of#thyvarbarSee [G-3] ofyvarlegendnolabeluseyvarnames, not labels, in legendyvaroptions(oversubopts)oversubopt sforyvars; seldom specifiedshowyvarslabelyvarsonxaxis; seldom specifiedblabel(..)add labels to barsSee [G-3]legendoptionsand [G-3] numericalyaxis on right (top)xalternateput categoricalxaxis on top (right)exclude0do not forceyaxis to include 0yreversereverseyaxisaxisscaleoptionsy-a xis scaling and lookaxislabeloptionsy-axis labelingytitle(.)
3 Y-axis titlingSee [G-3]axisscaleoptions, [G-3]axislabeloptions, and [G-3] bar Bar charts 3titleandotheroptionsDescriptiontext(..) add text on graph;xrange[0, 100]yline(..)addylines to graphaspectoptionconstrain aspect ratio of plot regionstdoptionstitles, graph size, saving to diskby(varlist,..)repeat for subgroupsSee [G-3]addedtextoptions, [G-3]addedlineoptions, [G-3]aspectoption, [G-3]stdoptions, and[G-3] used inover(varname,oversubopts)and, on rare occasion, inyvaroptions(oversubopts) areoversuboptsDescriptionrelabel(#"text" ..)change axis labelslabel(cataxislabeloptions)renditio n of labelsaxis(cataxislineoptions)rendition of axis linegap([*]#)gap between bars withinover()categorysort(varname)put bars in prespecified ordersort(#)put bars in height ordersort((stat)varname)put bars in derived orderdescendingreverse default or specified bar orderreversereverse scale to run from maximum to minimumSee [G-3]cataxislabeloptionsand [G-3] ,fweights, andpweights are allowed; see[U] weightand see note concerningweights in [D] >Bar chartDescriptiongraph bardraws vertical bar charts.
4 In a vertical bar chart, theyaxis is numerical, and thexaxis is graph bar (mean)numeric_var, over(cat_var)ynumeric_varmust be numeric;7statistics of it are shown be numeric or string;it is shown on the group4graph bar Bar chartsgraph hbardraws horizontal bar charts. In a horizontal bar chart, the numerical axis is still calledtheyaxis, and the categorical axis is still called thexaxis, butyis presented horizontally, graph hbar (mean)numeric_var, over(cat_var)xfirst groupsame conceptual layout:numeric_varstill appearsony,cat_varonxsecond 7 The Syntax for vertical and horizontal bar charts is the same; all that is required is are presented under the following headings:groupoptionsyvaroptionslookofba roptionslegendingoptionsaxisoptionstitle andotheroptionsSuboptions for use with over( ) and yvaroptions( )groupoptionsover(varname[,oversubopts]) specifies a categorical variable over which theyvarsare to be string or numeric.
5 Up to twoover()options may be specified whenmultipleyvarsare specified, and up to threeover()s may be specified when oneyvaris specified;options may be specified; seeExamples of syntaxandMultiple over( )s (repeating the bars)underRemarks and that missing subcategories be omitted. For instance, consider. graph bar (mean) y, over(division) over(region)Say that one of the divisions has no data for one of the regions, either because there are no suchobservations or becausey==.for such observations. In the resulting chart, the bar will be missing:div_1 div_2 div_3 div_1 div_2 div_3region_1 region_2graph bar Bar charts 5If you specifynofill, the missing category will be removed from the chart:div_1 div_2 div_3 div_1 div_3region_1 region_2missingspecifies that missing values of theover()variables be kept as their own categories, onefor., another , etc. The default is to act as if such observations simply did not appear inthe dataset; the observations are ignored.
6 Anover()variable is considered to be missing if it isnumeric and contains a missing value or if it is string and contains .allcategoriesspecifies that all categories in the entire dataset be retained for theover() specified withoutallcategories, the graph is drawn, completely excludingany categories for theover()variables that do not occur in the specified subsample. With theallcategoriesoption, categories that do not occur in the subsample still appear in the legend, andzero-height bars are drawn where these categories would appear. Such behavior can be convenientwhen comparing graphs of subsamples that do not include completely common categories for allover()variables. This option has an effect only wheniforinis specified or if there are missingvalues in the not be combined withby().yvaroptionsascategoryspecifies that theyvarsbe treated as the firstover()group; seeTreatment of barsunderRemarks and a useful you specifyascategory, results are the same as if you specified oneyvarand introduceda new firstover()variable.
7 Anyplace you read in the documentation that something is done overthe firstover()category, or using the firstover()category, it will be done over or that you specified. graph bar y1 y2 y3, ascategorywhatever_other_optionsThe results will be the same as if you typed. graph bary, over(newcategoryvariable)whatever_other_ optionswith a long rather than wide dataset in that the firstover()group be treated asyvars. SeeTreatment of barsunderRemarks and you specifyasyvars, results are the same as if you removed the firstover()group andintroduced multipleyvars. If you previously hadkyvarsand, in your firstover()category,Ggroups, results will be the same as if you specifiedk Gyvarsand removed theover(). Anyplaceyou read in the documentation that something is done over theyvarsor using theyvars, it will bedone over or using the firstover() that you specified. graph bar y, over(group) asyvarswhatever_other_optionsResults will be the same as if you typed.
8 Graph bary1 y2 y3..,whatever_other_options6graph bar Bar chartswith a wide rather than a long dataset in memory. Variablesy1,y2,.., are sometimes called that bar heights be based on percentages thatyvarirepresents of all theyvars. That is,. graph bar (mean) inc_male inc_femalewould produce a chart with bar height reflecting average graph bar (mean) inc_male inc_female, percentagewould produce a chart with the bar heights being 100 incmale/(incmale+incfemale)and 100 incfemale/(incmale+incfemale).If you have oneyvarand want percentages calculated over the firstover()group, specify theasyvarsoption. For instance,. graph bar (mean) wage, over(i) over(j)would produce a chart where bar heights reflect mean graph bar (mean) wage, over(i) over(j) asyvars percentageswould produce a chart where bar heights are100 (meanij imeanij)Optionstackis often combined with that theyvarbars be graph bar (mean) inc_male inc_female, over(region) percentage stackwould produce a chart with all bars being the same height, 100%.
9 Each bar would be two barsstacked (percentage ofincmaleand percentage ofincfemale), so the division would showthe relative shares ofincmaleandincfemaleof total stack bars over the firstover()group, specify theasyvarsoption:. graph bar (mean) wage, over(sex) over(region) asyvars percentage stackcwspecifies casewise deletion. Ifcwis specified, observations for which any of theyvarsare missingare ignored. The default is to calculate the requested statistics by using all the data (*#)andoutergap(#)specify the gap between the edge of the graph to the beginningof the first bar and the end of the last bar to the edge of the (*#)specifies that the default be modified. Specifyingoutergap(* )increases thegap by 20%, and specifyingoutergap(*.8)reduces the gap by 20%.outergap(#)specifies the gap as a percentage-of-bar-width (50)specifies thatthe gap be half the bar (#)specifies the gap to be left betweenyvarbars as a percentage-of-bar-width units.
10 Thedefault isbargap(0), meaning that bars bar Bar charts 7bargap()may be specified as positive or negative (10)puts a small gap betweenthe bars (the precise amount being 10% of the width of the bars).bargap(-30)overlaps the barsby 30%.bargap()affects only theyvarbars. If you want to change the gap for the first, second, or thirdover()groups, specify theoversuboptgap()inside theover()itself; seeSuboptions for usewith over( ) and yvaroptions( ) (#)andintensity(*#)specify the intensity of the color used to fill the inside of (#)specifies the intensity, andintensity(*#)specifies the intensity relative tothe default, the bar is filled with the color of its border, attenuated. Specifyintensity(*#),#<1, to attenuate it more and specifyintensity(*#),#>1, to amplify (0)if you do not want the bar filled at all. Specifyintensity(100)if youwant the bar to have the same intensity as the bar s (#)andlintensity(*#)specify the intensity of the line used to outline the (#)specifies the intensity, andlintensity(*#)specifies the intensity relative tothe default, the bar is outlined at the same intensity at which it is filled or at an amplificationof that, which depending on your chosen scheme; see [G-4]schemes intro.