1 session 5 graphs for data analysis. 2 objectives to be able to use stata to produce exploratory...

20
1 SESSION 5 Graphs for data analysis

Upload: adam-walker

Post on 28-Mar-2015

220 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: 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

1

SESSION 5

Graphs for data analysis

Page 2: 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

2

Objectives

To be able to use STATA to produce exploratory and presentation graphs

In particularBar ChartsHistograms and Box PlotsScatter Plots and Scatterplot Matrices

Page 3: 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

3

Graphics Menu

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

Page 4: 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

5

Graphics Histogram dialogue

Page 5: 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

6

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

Page 6: 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

7

Results

Page 7: 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

8

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?

Page 8: 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

9

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

Page 9: 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

10

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

Page 10: 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

11

Bar chart with labels

• Look at the resulting graph) Is it better?

Page 11: 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

12

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!

Page 12: 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

13

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

Page 13: 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

14

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 Angle is 45 .

Page 14: 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

15

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 2 Rows.

Click Accept, then OK.

See next slide for the resulting graph.

Page 15: 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

16

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

Page 16: 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

17

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

Page 17: 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

18

Opening a new Do file

Through the Do-file Editor icon

or Window, or press <Ctrl> 8

Page 18: 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

19

Example of a Do-file

To run a Do-file, use the Do current fileicon or use Tools Do

Page 19: 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

20

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.

Page 20: 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

21

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.