1 / 24

Advanced Stata Workshop

Advanced Stata Workshop. FHSS Research Support Center. Presentation Layout. Visualization and Graphing Macros and Looping Panel and Survey Data Postestimation. Visualization and Graphing in Stata. Intro To Graphing In Stata. “graph” is often optional. So is “ twoway ” in this case.

sanjiv
Télécharger la présentation

Advanced Stata Workshop

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Advanced Stata Workshop FHSS Research Support Center

  2. Presentation Layout • Visualization and Graphing • Macros and Looping • Panel and Survey Data • Postestimation

  3. Visualization and Graphing in Stata

  4. Intro To Graphing In Stata “graph” is often optional. So is “twoway” in this case. Note: Nearly all graphing commands start with “graph”, and “twoway” is a large family of graphs.

  5. Creating Multiple Graphs with “by():” Note that the value label is displayed above the graphs, and the variable label is displayed in the bottom right hand corner.

  6. Overlaying “twoway” graphs The || tells Stata to put the second graph on top of the first one – order matters! You don’t need to type “twoway” twice; it applies to both. This is another way of writing the command – it doesn’t matter which one you use.

  7. "by()" statements with overlaid graphs “qfitci” is a type of graph which plots the prediction line from a quadratic regression, and adds a confidence interval. The “stdf” option specifies that the confidence interval be created on the basis stdf is an option of qfitci. by(foreign) is an option of twoway.

  8. "by()" statements with overlaid graphs Another way of writing the previous command is: So: This was is easier to read. This way is easier to type.

  9. Graphs with Many Options and Overlays You can make pretty impressive graphs just from code, if you overlay the graphs and specify certain options like: multiple axes, notes, titles and subtitles, axis titles and labels, and legends.

  10. Code for Previous Graph This may look scary, but it is actually fairly straightforward. See the accompanying do-file for explanation of each component.

  11. Using the Graph Editor It is often easier to make changes in the graph editor than to specify all the options in code. Let’s make graph 1 into graph 2 by using the graph editor tools.

  12. Recording Edits in the Graph Editor Before you start making changes, click the record button. After you are done, click it again, and save your changes as a recording so you can “play” them back later. We will save this recording as advanced_workshop_1.

  13. Play Your Graph Recording You can create a graph, open the graph editor, click the green play button, and then play back your recorded edits. Or, you can play your edits right from the code: You can run your recorded edits on a graph of a different type, though in this case not all of your edits will make sense: You can also run all of your recorded edits on a different graph, and just change the title:

  14. Storing and Moving Your Recordings Graph recordings are stored as .grec files in your “personal” folder, under the “grec” folder. Type “personal” to see where this is; normally it is C:\ado\personal. So by default Stata should store your .grec files in C:\ado\personal\grec. Unfortunately, if you are not faculty, you are probably using lab computers to use Stata, and when they are re-imaged, you will lose the files in your grec folder. So you can store the recordings on your flash drive by clicking the Browse button when you save your recording. Now, when you are in the graph editor and click the play button, your recording will not appear in the list because it is not stored where Stata knows to look for it. Never fear, just click Browse, and navigate to where your .grec file is. If you want your recording to be available right from code, as in play(advanced_workshop_1), you will need to move it (at least temporarily) to the “grec” folder, or write the directory location in the code: play(E:\flashdrive\Graph Recordings\advanced_workshop_1)

  15. Using Schemes in Graphing Recordings are great if you are going to be making the same kind of graph a lot. But a recording for a scatter plot will hardly affect a histogram at all, and might even make it look terrible. If you want to change the look of all graphs that you make, you may want to make a scheme. Schemes are text files which tell Stata how to draw graphs.

  16. More on Schemes Schemes are very powerful, because they let your implement a certain look without specifying a long series of options in every graph, or running every graph through the graph editor. However, creating schemes is fairly time consuming. For more on creating your own schemes, see: http://www3.eeg.uminho.pt/economia/nipe/2010_Stata_UGM/papers/Rising.pdf And http://www.ats.ucla.edu/stat/stata/seminars/stata_graph/graphsem.txt

  17. Manipulating Graphs: Memory vs. Disk • When you draw a graph, it is stored in memory, under the name Graph. • If you draw another graph, it replaces the previous one in memory, and is now called Graph. • If you want to have multiple graphs up at the same time, you can use the name option. • graph save moves your graph from memory to disk, saving it as a .gph file. • graph dir lists all graphs in memory and on disk (in the current directory) • graph drop drops a graph from memory. Graphs contain the data files they represent, so if the dataset is large, they can actually take up quite a bit of memory.

  18. Manipulating Graphs Demo • See do file for demo

  19. More Example Graphs Note: Annotated code is in the do file for all of these Histogram, with overlaid normal distribution

  20. More Example Graphs Use graph bar to make bar graphs

  21. More Example Graphs Use graph combine to combine 3 graphs into one:

  22. More Example Graphs Graph matrix is a great alternative to a correlation matrix to investigate relationships between variables

  23. More Example Graphs Get data labels (called marker labels in Stata) from the values of another variable

  24. More Example Graphs Xtline from a panel data set can overlay lines for each value of panel variable. The labels on the x-axis are often a bit off to start though, as shown.

More Related