Está en la página 1de 8

# 2/19/2017 Stata:GraphingDistributionsPsychstatistics

Psychstatistics
Trying to be thoughtful

Home
Current Research
Tutorials
Blog

24 Nov 2010

## Tags: Stata and Tutorial

Graphing Distributions
This post will demonstrate how:

## 1. Use the `twoway function plotting command to visualize distributions

2. Add colored shading to a graph to visualize portions of a distribution

## The twowayfunction command

The twowayfunction plotting command is used to plot functions, such as y=
mx+b . If we want to plot the density of a normal distribution across a range of x
values, we type y=normalden(x) . You can also include graphing options available
to twoway plots (e.g., xtitle ).

twowayfunctiony=normalden(x),range(44)xtitle("{it:x}")///
ytitle("Density")title("StandardNormalDistribution")

http://www.psychstatistics.com/2010/11/24/statagraphingdistributions/ 1/8
2/19/2017 Stata:GraphingDistributionsPsychstatistics

Suppose we want to shade parts of a distribution above (or below) a particular
critical value. For example, we can shade a normal distribution above 1.96 and
below -1.96 if we want critical values for a two-tailed test with an alpha-level of
.05. To do this we will draw 3 graphs.

## 1. A normal curve from -4 to -1.96

2. A normal curve from -1.96 to 1.96
3. A normal curve from 1.96 to 4

The choice of -4 and 4 as upper and lower bounds is arbitrary. You can connect the
three graphs by using a double pipe, || , between calls to the twowayfunction
command. We will shade the area under the curve for #1 and #3 using the
recast(area) option of twowayfunction . We will assign the color of the
shading to dark navy blue using the color(dknavy) option. We will leave the area
under the curve for #2 unshaded.

twowayfunctiony=normalden(x),range(1.961.96)color(dknavy)||
///
functiony=normalden(x),range(41.96)recast(area)color(dknavy)
||///
functiony=normalden(x),range(1.964)recast(area)color(dknavy)
///
xtitle("{it:x}")///
ytitle("Density")title("CritialValuesforStandardNormal")///
subtitle("Twotailedtestand{&alpha}=.05")///
legend(off)xlabel(1.9601.96)

http://www.psychstatistics.com/2010/11/24/statagraphingdistributions/ 2/8
2/19/2017 Stata:GraphingDistributionsPsychstatistics

## We can repeat for a one-tailed test.

twowayfunctiony=normalden(x),range(41.64)color(dknavy)||///
functiony=normalden(x),range(1.644)recast(area)color(dknavy)
///
xtitle("{it:x}")///
ytitle("Density")title("CritialValuesforStandardNormal")///
subtitle("Onetailedtestand{&alpha}=.05")///
legend(off)xlabel(01.64)

## We can also visualize other distributions available in Stata. Below, I provide an

example of a t-distribution with 20 degrees of freedom

twowayfunctiony=tden(20,x),range(2.092.09)color(dknavy)||///
functiony=tden(20,x),range(42.09)recast(area)color(dknavy)||
///
functiony=tden(20,x),range(2.094)recast(area)color(dknavy)///

http://www.psychstatistics.com/2010/11/24/statagraphingdistributions/ 3/8
2/19/2017 Stata:GraphingDistributionsPsychstatistics

xtitle("{it:x}")///
ytitle("Density")title("CritialValuesfor{it:t}distributionwit
h20df")///
subtitle("Twotailedtestand{&alpha}=.05")///
legend(off)xlabel(2.0902.09)

Related Posts
LKJ Priors 27 Dec 2014
Beginning and Advanced SEM 14 Nov 2013
Predicted Scores and Residuals in Stata 01 Oct 2013

http://www.psychstatistics.com/2010/11/24/statagraphingdistributions/ 4/8
2/19/2017 Stata:GraphingDistributionsPsychstatistics

## Recommend Share SortbyBest

Startthediscussion

Bethefirsttocomment.

ALSOONPSYCHSTATISTICS

Stata:DescriptiveStatisticsMean, LKJPriors
median,variability 1comment2yearsago
1comment2yearsago MarkusGesmannShortand
bestcourseworkwritingStudents insightfulpost.Thankyouverymuch!
especiallythosewhohaveasubject
relatedtothisthingcangainsome
newideasandinformationon