



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Stata commands for module 7 of the statistics for sociologists course at the university of north carolina, chapel hill, focusing on inference for distributions. It includes functions for normal and student's t distributions, as well as instructions for calculating confidence intervals and performing one-sample tests.
Typology: Study notes
1 / 7
This page cannot be seen from the preview
Don't miss anything!




University of North Carolina Chapel Hill
Professor François Nielsen
followed by the name of the command in Stata.
For confidence intervals, also see page 35 of the Stata and SAS Guide pdf
(click on Documents in side bar; guide is linked under Software Documenta-
tion).
1.1 Normal Distribution Functions
P ( Z ≤ z ).
. display normal(1.207) .
. display invnormal(0.975)
1.2 Student t Distribution Functions
dent’s t distribution for df degrees of freedom; given t it returns the probability
P ( T > t ).
. display ttail(7, 1.960) .
(upper-tail) Student’s t distribution for df degrees of freedom; given p it returns
t such that P ( T > t ) = p.
. display invttail(7, 0.025)
1.3 Curve for Problem 7.113 p.
For IPS6e Problem 7.113 p.481 – Degrees of freedom and confidence interval
width.
This is how to draw the curve requested in this problem in Stata:
. twoway function y=invttail(x,0.025), range(2 100) yline(1.96)
This is how to do it in R:
curve(qt(0.975,x),2,100,xlab="Degrees of freedom", ylab="t*") abline(1.96,0,col="blue")
There are several ways to enter data in Stata to calculate confidence intervals
for the mean and one-sample test statistics. Here are three of them.
2.1 Method 1
A quick-and-dirty method from Andrew Ritchey. Take IPS6e Problem 7.
p.442 as an example. You have to enter 20 observations. In Stata, first clear
any data in memory. Then create a data frame with 20 observations and create
a variable with all values missing:
. clear . set obs 20 . gen mpg=.
Then go to the data editor (Data/Data Editor, or click the icon) and replace the
missing values with the actual values. Then close the Data Editor (click on the
×). Your data are ready to use. See below.
2.2 Method 2
Another technique from Michele Easter. You want to enter 9 observations. After
. clear . input var
var
2.3 Method 3
Still another technique that is a time-saver for moderately long data sets from
the textbook. Use the disk that comes with the text and navigate to the data
sets, and go the the Excel folder. The data for Problem 7.24 p. 442 are under
. * lower bound of CI . display 43.17 - 2.
. * upper bound . display 43.17 + 2.
Now we do the CI the easy way.
. ci mpg
Variable | Obs Mean Std. Err. [95% Conf. Interval] -------------+--------------------------------------------------------------- mpg | 20 43.17 .9872104 41.10374 45.
The following two examples involve inputting data using the keyboard, but in
general it is easier just to go into the Data Editor, or copy and paste from an
already-entered Excel spreadsheet.
. input var
var
. su var
Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- var | 9 3.133333 .1581139 2.9 3.
The mean for this sample is 3.133333. Now we would like to do a t-test to
assess how likely it is that the true mean is greater than 3. Stata tests whether
the μ > 3, μ = 3, or μ < 3 at the same time.
. ttest var=
Variable | Obs Mean Std. Err. Std. Dev. [95% Conf. Interval] ---------+-------------------------------------------------------------------- var | 9 3.133333 .0527046 .1581139 3.011796 3.
mean = mean(var) t = 2. Ho: mean = 3 degrees of freedom = 8
Ha: mean < 3 Ha: mean != 3 Ha: mean > 3 Pr(T < t) = 0.9824 Pr(|T| > |t|) = 0.0353 Pr(T > t) = 0.
Stata by default assigns a 95% confidence interval, but this can be changed
would enter the command (output not shown):
. ttest var=3, level(90) ...
This example is very similar.
. input x
x
Variable | Obs Mean Std. Err. Std. Dev. [95% Conf. Interval] ---------+-------------------------------------------------------------------- x | 6 7333.333 494.4132 1211.06 6062.404 8604.
mean = mean(x) t = 14. Ho: mean = 0 degrees of freedom = 5
Ha: mean < 0 Ha: mean != 0 Ha: mean > 0 Pr(T < t) = 1.0000 Pr(|T| > |t|) = 0.0000 Pr(T > t) = 0.
under Datasets), do a t-test to see whether State cabinets under Democratic
. ttesti 17 .1712353 .0822401 22 .2398636 .1350461, unequal ... . ttesti 17 .1712353 .0822401 22 .2398636. ...