|
|
|
||||
|
|
|||||
. ttest
oneway
anova
test
regress
predict
. use hsb2, clear
We will continue to use the Highschool and Beyond dataset. The file 'hsb2.dta' has correct and complete data for all of the variables.
. ttest write=50
This example involves the single-sample t-test, testing whether the sample was drawn from a population with a mean of 50. By the way, the standardized writing test in this sample was normed nationally with a mean of 50.
. ttest write=read
This example makes use of the t-test for dependent samples. In this case, we are testing whether there is a significant difference betweent the math and the science test scores.
. ttest write, by(female)
ttest write, by(female) unequal
sdtest write, by(female)
The t-test for independent groups comes in two varities: pooled variance and unequal variance. We want to look at the differences in writing test scores between 'school types.' We will begin with the ttest for independent groups with pooled variances and compare the results to the ttest for independent groups using unequal variance.
There is a test for heterogeneity of variance, sdtest, but it is overly sensitive to nonnormality and statisticians do not recommend using it to screen for heterogeneity of variance.
. oneway write prog, tabulate
anova write prog
sort prog
by prog: summarize write
table prog, contents(n write mean write sd write)
Here are two different ways to perform a one-way analysis of variance (ANOVA). They both give the exact same answer. The most visible difference is that oneway includes a test for homogeneity of variance.
. anova write female prog female*prog
This example demonstrates a 3 X 3 factorial analysis of variance.
. regress write read
regress write read, beta
predict pre1
generate pre2 = 23.95944 + .5517051*read
list pre1 pre2
graph pre1 write read, symbol(io) connect(L.)
graph pre1 write read, symbol(io) connect(L.) jitter(2)
These are two examples of simple linear regression. The first one displays confidence intervals for the regression coefficients while the second one displays standardized regression coefficients along with the 'regular' regression coefficients. The predict command computes a predicted science score for each observation. Compare 'pre1' with 'pre2' that was created using the generate command. The graph command, in this example, displays a scatter plot of read and write along with showing the regression regression line of science on math. The second example uses the jitter option to help see the points where there are multiple observations on one point.
. regress write read math
regress write read math female
This time we have two examples of a multiple regression, the first one with two predictor variables and the second one with three.
anova & regress are just two of many estimation procedures available in Stata. A partial list is given in the table below:
| anova | analysis of variance and covariance |
| arch | autoregressive conditional heterosce. family of estimators |
| arima | autoregressive integrated moving average models |
| bsqreg | quantile regression with bootstrapped standard errors |
| clogit | conditional logistic regression |
| cnreg | censored-normal regression |
| cnsreg | constrained linear regression |
| ereg | maximum-likelihood exponential distribution models |
| glm | generalized linear models |
| glogit | weighted least squares logit on grouped data |
| gprobit | weighted least squares probit on grouped data |
| ivreg | instrumental variable and two-stage least squares regression |
| lnormal | maximum-likelihood lognormal distribution models |
| logistic | logistic regression |
| logit | maximum-likelihood logit regression |
| mlogit | maximum-likelihood multinomial logit models |
| mvreg | multivariate regression |
| nbreg | maximum-likelihood negative binomial regression |
| nl | nonlinear least squares |
| ologit | maximum-likelihood ordered logit |
| oprobit | maximum-likelihood ordered probit |
| poisson | maximum-likelihood poisson regression |
| probit | maximum-likelihood probit estimation |
| qreg | quantile regression |
| reg3 | three-stage least squares regression |
| regress | linear regression |
| rreg | robust regression using IRLS |
| sureg | seemingly unrelated regression |
| tobit | tobit regression |
| vwls | variance-weighted least squares regression |
| zinb | zero-inflated negative binomial model |
| zip | zero-inflated poisson models |
test & predict are commands that can be used in conjuction with estimation procedures. There are too many combinations of estimation, predict and test to get into in this class, other than to say that they provide very powerful tools for researchers and are worth the time spent learning them.
. use hsb2, clear
ttest math=50
ttest math, by(sch)
oneway math sci
oneway math prog
anova math prog ses prog*ses
test ses / prog*ses
regress science math
regress science math, beta
regress science math read
regress science math read write
The Stata Class Notes are available on the World Wide Web by visiting ...
http://www.ats.ucla.edu/stat/stata/notes/
The dataset hsb2.dta can be loaded directly into Stata, over the Internet, using the
following command:
use http://www.ats.ucla.edu/stat/stata/notes/hsb2
UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services