1 / 20

SESSION 5

SESSION 5. Graphs for data analysis. Objectives. To be able to use STATA to produce exploratory and presentation graphs In particular Bar Charts Histograms and Box Plots Scatter Plots and Scatterplot Matrices. Graphics Menu.

mizell
Télécharger la présentation

SESSION 5

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. SESSION 5 Graphs for data analysis

  2. Objectives • To be able to use STATA to produce exploratory and presentation graphs • In particular • Bar Charts • Histograms and Box Plots • Scatter Plots and Scatterplot Matrices

  3. Graphics Menu Dialogue resulting from Two-way graph (scatter, line, etc.) and its option Create

  4. Graphics Histogram dialogue

  5. Completing the dialogue box • In the histogram dialogue box, select the variable q34. This has codes 1 to 7 for main sources of drinking water. • Select discrete • Specify that the y axis should show Frequency • Note that after clicking on Submit, the command histogram q34, discrete frequency appears in the Command & Results windows

  6. Results

  7. Improving your bar chart • Use Graphics  Histogram • Ensure dialogue is as shown in slide 5 • Click on Bar Properties and select Bar gap as 30 (see Figure on left). • Click Accept, then OK. • Is the graph better?

  8. Learning to add bar labels • Return to the full Histogram dialogue above • Select option “X-Axis” , then click on • Major tick/label properties. In the resulting dialogue, give the Axis rule as “Custom” and give the Custom rule as 1(1)7 – see figure on left of slide below. • Move also to the Labels option and check Use value labels below and click Accept • See dialogue as shown in next slide

  9. Adding bar labels The 1(1)7 Rule means – place ticks (and therefore labels) from 1 to 7 in steps of 1 on the X axis

  10. Bar chart with labels • Look at the resulting graph) Is it better?

  11. Using Stata commands • The command to produce the above, on one line, is: histogram q34, discrete frequency gap(30) xlabel( 1(1)7, valuelabel) • If there were no labels, or we wanted shorter ones, then use the command (again on one line): histogram q34, discrete frequency gap(30) xlabel(1 "pipe" 2 "pub" 3 "well1" 4 "well2" 5 "riv" 6 "vend" 7 "oth") • BUT DO NOT TYPE THESE YET!

  12. Bar charts to aid comparisons e.g. employment across gender Our aim now is to display results of this table in the form of two bar charts, one for males and one for females. Above produced using the command .tabulate q130 q11, column nofreq

  13. Menu sequence for producing the corresponding charts • Start with the Graphics  Histogram dialogue • The variable q130 gives the employment class of the head of the household. Select this variable, request Y-Axis to display percent and ensure bar gap is still at 30. • In the X-Axis option, click on Major tick/label properties, and ensure Custom Rule is now 1(1)11, then move to Labels and ensure use value labels are ticked, and Angleis 45 .

  14. producing the charts cont… • Now go to the By option, and select q11(i.e. sex), as variable for subgraphs. • Click on Subgroup organisation and in the resulting dialogue, request Rows/Columns to be 2Rows. • Click Accept, then OK. • See next slide for the resulting graph.

  15. Bar charts for comparisons This is an example of a graph that would be difficult with a spreadsheet Employment for Males shown separately from that for females

  16. Do files • Sometimes it is useful to use commands • Stata commands can become quite complicated. • Sometimes useful to run a set of commands. • They can be saved in a “Do” file. What is a “Do” file? • A set of commands • In other packages these are called syntax or batch files • Why use do files • Good practice in data management • Repeatability of steps

  17. Opening a new Do file • Through the Do-file Editor icon • or Window, • or press <Ctrl> 8

  18. Example of a Do-file To run a Do-file, use the Do current fileicon or use Tools  Do

  19. Making a Do file • Open a new Do file • Copy & paste, or type in one or more of the graphics commands on slide 12 or others you have produced • Include some comments, preceded by a * or included between /* <comments> */ to indicate the analysis being done • Then save the Do file. This will have .do as its extension.

  20. Your Turn Now…. • Go through Section 6.3 • Use the same histogram dialogue (page 76) to go through Section 6.4 • Do the following exercises from the guide, saving your commands in a Do file as you go along • Histogram and box plots for a continuous variable, in sections 6.7.1 and 6.7.3 • Scatter plots, sections 6.8.2 & 6.8.3 • Load your own data into Stata, and produce graphs that address an objective of interest.

More Related