Stata 1, Graphics - PowerPoint PPT Presentation

1 / 33
About This Presentation
Title:

Stata 1, Graphics

Description:

Problem example. Lunch meals per week. Table of means (around 5 per week) Linear regression ... (fpfitci weight parity3) (lfit weight parity3) , legend(off) ... – PowerPoint PPT presentation

Number of Views:101
Avg rating:3.0/5.0
Slides: 34
Provided by: heins1
Category:

less

Transcript and Presenter's Notes

Title: Stata 1, Graphics


1
Stata 1, Graphics
  • Hein Stigum
  • Presentation, data and programs at
  • http//folk.uio.no/heins/

2
Why use graphs?
3
Problem example
  • Lunch meals per week
  • Table of means (around 5 per week)
  • Linear regression

4
Problem example 2
  • Iron level
  • Both linear and logistic regression
  • Opposite results

5
Structure of talk
  • Order
  • Work/presentation plots
  • Plot types
  • Outcome type
  • Focus
  • The right plot
  • The commands

6
Plot types
7
Plottypes
8
Continuous outcome
9
Univariate
  • Density
  • kdensity weight
  • Boxplot
  • graph hbox weight

10
Density with box information
11
Bivariate
  • Scatter
  • scatter weight gest

12
Scatter and density plots for many types of data
13
Twoway density
  • Syntax
  • graph twoway (plot1, opts) (plot2, opts), opts
  • One plot
  • kdensity x
  • Two plots overlaid
  • twoway ( kdensity weight if sex1, lcolor(blue)
    ) ///
  • ( kdensity weight if sex2, lcolor(red) )
  • Side by side
  • twoway ( kdensity weight ), by(sex)

14
Twoway scatter fit
  • Syntax
  • graph twoway (plot1, opts) (plot2, opts), opts
  • Examples
  • scatter y x
  • twoway (scatter y x) (fpfitci y x) (lfit y x)

Fitlines
15
Continuous by 3 categories
  • Is birth weight the same over parity?

Density plot
Scatterplot
Equal means? Linear effect? Outliers?
Equal variances?
16
Continuous by 3 categories
Scatterplot
  • twoway (scatter weight parity3) (fpfitci
    weight parity3) (lfit weight
    parity3) , legend(off)
  • Look for
  • Outliers (all analyses)
  • Non-linear effects (regression)

17
Continuous by 3 categories
Density plot
  • twoway
  • (kdensity weight if parity30, lcol(black))
  • (kdensity weight if parity31, lcol(blue))
  • (kdensity weight if parity32, lcol(red))
  • , yscale(off)
  • Look for
  • Different locations
  • Different shapes (ANOVA, regression)

18
Twoway density options
  • kdensity x, normal add normal curve
  • kdensity x, area(400) frequency, N400
  • display r(width) previous width
  • kdensity x, width(80) less smoothing

19
Twoway options
  • Syntax
  • graph twoway (plot1, opts) (plot2, opts), opts
  • Options
  • lcolor(red) line color
  • lpattern(.-) line pattern
  • lwidth(2) line width 2
  • legend(
  • ring(0) legend inside plot
  • pos(2) legend at 2 oclock position
  • col(1) legends in 1 column
  • label(1 First) legend label plot 1
  • label(2 Second) legend label plot 2
  • )

20
Continuous by continuous
  • twoway (scatter weight gest) (fpfitci weight
    gest) (lfit weight gest)
  • Look for
  • Main effect (line)
  • Non-linearity (smooth)
  • outliers

21
More twoway options
  • Syntax
  • graph twoway (plot1, opts) (plot2, opts), opts
  • Options
  • msize(0.5) marker size
  • mlabel(id) marker label variable id
  • xline(24) line at x24
  • scale(1.5) all elements 1.5larger

22
Mark outliers
  • twoway (scatter weight gest) (scatter weight
    gest if gestgt400, mlabel(id))

23
Titles, legend, labels and scale
24
Titles
scatter weight gest, title("title")
subtitle("subtitle") /// xtitle("xtitle")
ytitle("ytitle") note("note")
25
Legend
  • , legend( ring(0) pos(11) col(1) label(1
    Boys, N283) label(2 Girls, N270) )
  • , legend(off)

26
Axis scale and label
scatter weight gest, xscale(range(250 310))
/// xlabel( 250(20)310 281)
27
Categorical outcome
28
Comparing means or proportions
29
Comparing means/prop. better
  • preserve save data
  • collapse (mean) v1 v2 v3, by(parity) aggregate
  • list list the new data
  • twoway (scatter v1 parity) (line v1 parity) ///
  • (scatter v2 parity) (line v2 parity) ///
  • (scatter v3 parity) (line v3 parity)
  • restore restore original data

30
Binary outcome
31
Scatter binary by countinuous
32
Binary with rug and smooth
  • gen yy.
  • replace yy 0.02(lowbw0) 0.98(lowbw1)
  • twoway (rspike yy lowbw gest) (fpfit
    lowbw gest)

33
Regression results
Write a Comment
User Comments (0)
About PowerShow.com