
To make the options more obvious to the reader, I put the comma at the start of a new line: graph twoway (lfitci setting effort) /// Here we specify both as options to the twoway command. You could specify a label for the y-axis using the ytitle() option, and omit the (rather obvious) legend using legend(off).

Note that this command doesn’t label the y-axis but uses a legend instead. (There is also a qfitci band for quadratic fits.) Because the confidence band can obscure some points we draw the region first and the points later graph twoway (lfitci setting effort) /// Stata can do this with the lfitci plot type, which draws the confidence region as a gray band. Now suppose we wanted to put confidence bands around the regression line. (One can also combine plots using two horizontal bars || to separate them.) graph twoway (scatter setting effort) /// (There is also a qfit plot for quadratic fits.) This can be combined with the scatter plot by enclosing each sub-plot in parenthesis. Stata can do all that in one step using the lfit plot type. In some packages you would need to run a regression, compute the fitted line, and then plot it. Suppose we want to show the fitted regression line as well. We will now add a few bells and whistles. The command may be abbreviated to twoway scatter, or just scatter if that is the only plot on the graph. Stata labels the axes using the variable labels, if they are defined, or variable names if not. To produce a simple scatterplot of fertility change by social setting you use the command graph twoway scatter change setting To whet your appetite, here’s the plot that we will produce in this section: infile str14 country setting effort change /// To read the data from net-aware Stata type. In this section I will illustrate a few plots using the data on fertility decline first used in Section 2.1. I do not recomment this practice, however, because it conflicts with the goals of documenting and ensuring reproducibility of all the steps in your research.Īll the graphs in this section (except where noted) use a custom scheme with blue titles and a white background, but otherwise should look the same as your own graphs. Stata 10 introduced a graphics editor that can be used to modify a graph interactively. I will also describe briefly bar plots, available through the bar subcommand, and other plot types. These are available in Stata through the twoway subcommand, which in turn has many sub-subcommands or plot types, the most important of which are scatter and line. The most common graphs in statistics are X-Y plots showing points or lines. Stata has excellent graphic facilities, accessible through the graph command, see help graph for an overview. graph export "stacked graph.Introduction Data Management Graphics Programming 3 Stata Graphics Graph export "stacked graph.png", replace width(2000) Legend(off) /// no legend, aspect is the shape of the figure. Text(4 1.2 "Q1", color(white)) /// first number is y second is x. Xscale(log) /// make the x axis log scale , /// if you modify this file and it stops working, check the placement of this comma Import excel "stacked bar graph data.xlsx", firstrow clear // make sure that excel do file for making this horizontal stacked bar graph Make sure that you save and close Excel before running the. You can tweak the numbers by editing the Excel file, hitting save/close, and rerunning the. I made this for quartiles, hence the q1-4 names. Group is the number of the individual bars, bottom is the bottom of the first segment of a bar, q1 is the top of the first segment of each bar. More importantly, it set the working directory as the same folder that also contains the Excel file.

#STATA COLORS WINDOWS#
do file from Windows explorer so that Stata set the working directory as the same folder that contains the. I made an Excel file called stacked bar graph data.xlsx that I saved in the same folder as a.
