 x1, x2 and x3 are more likely to have a contract with middlemen, and x4, x5 and x6 are less likely to have a contract.
 Marginal effect (ME): x1, x2 and x3 are N% more likely to have a contract with middlemen.
 The predicted probabilities are limited between 0 and 1.
 Probit are estimated using the ML method.
 an increase in x increases/decreases the likelihood that y=1
 an increase in x makes the outcome of 1 more likely.
 We interpret the sign of the coefficient but not the magnitude.
 The magnitude can’t be interpreted using the coefficient because different model has a different scales of coefficient.
 Interpret ME: an increase in x increase the probability y=1, by the marginal effect expressed as a percent. We can interpret both sign and magnitude.
 Predicted probability indicate the likelihood of y=1, if the predicted prob is greater than 0.5 we can predict that y=1, others y=0.
Here is the important syntax for probit analysis. Thanks to Ani Kutchova
[youtube]https://www.youtube.com/watch?v=wU1DVbpD9SY&feature=player_embedded[/youtube]
global ylist Contract_e1
global xlist Age d_notgoingschool No_of_child Marital_status social_group own_boat human_spec frequency Riskbehavior search_costs nego_costs monitor_costs trust market_info connected_lending Andon_fisher d_javanese d_bugis uncertainty
describe $ylist $xlist
summarize $ylist $xlist
list $ylist $xlist in 1/10
tab $ylist
reg $ylist $xlist
probit $ylist $xlist
quietly probit $ylist $xlist
margins, dydx(*) atmeans
margins, dydx(*)
quietly probit $ylist $xlist
predict pprobit, pr
quietly probit $ylist $xlist
estat classification
[youtube]http://www.youtube.com/watch?v=1cFYlMjEzc[/youtube]
[youtube]http://www.youtube.com/watch?v=66Mn9GAWrAE[/youtube]
[youtube]http://www.youtube.com/watch?v=wU1DVbpD9SY[/youtube]
Source: http://www.ats.ucla.edu/stat/mult_pkg/whatstat/nominal_ordinal_interval.htm
What is the difference between categorical, ordinal and interval variables?
In talking about variables, sometimes you hear variables being described as categorical (or sometimes nominal), or ordinal, or interval. Below we will define these terms and explain why they are important.
Categorical
A categorical variable (sometimes called a nominal variable) is one that has two or more categories, but there is no intrinsic ordering to the categories. For example, gender is a categorical variable having two categories (male and female) and there is no intrinsic ordering to the categories. Hair color is also a categorical variable having a number of categories (blonde, brown, brunette, red, etc.) and again, there is no agreed way to order these from highest to lowest. A purely categorical variable is one that simply allows you to assign categories but you cannot clearly order the variables. If the variable has a clear ordering, then that variable would be an ordinal variable, as described below.
Ordinal
An ordinal variable is similar to a categorical variable. The difference between the two is that there is a clear ordering of the variables. For example, suppose you have a variable, economic status, with three categories (low, medium and high). In addition to being able to classify people into these three categories, you can order the categories as low, medium and high. Now consider a variable like educational experience (with values such as elementary school graduate, high school graduate, some college and college graduate). These also can be ordered as elementary school, high school, some college, and college graduate. Even though we can order these from lowest to highest, the spacing between the values may not be the same across the levels of the variables. Say we assign scores 1, 2, 3 and 4 to these four levels of educational experience and we compare the difference in education between categories one and two with the difference in educational experience between categories two and three, or the difference between categories three and four. The difference between categories one and two (elementary and high school) is probably much bigger than the difference between categories two and three (high school and some college). In this example, we can order the people in level of educational experience but the size of the difference between categories is inconsistent (because the spacing between categories one and two is bigger than categories two and three). If these categories were equally spaced, then the variable would be an interval variable.
Interval
An interval variable is similar to an ordinal variable, except that the intervals between the values of the interval variable are equally spaced. For example, suppose you have a variable such as annual income that is measured in dollars, and we have three people who make $10,000, $15,000 and $20,000. The second person makes $5,000 more than the first person and $5,000 less than the third person, and the size of these intervals is the same. If there were two other people who make $90,000 and $95,000, the size of that interval between these two people is also the same ($5,000).
Why does it matter whether a variable is categorical, ordinal or interval?
Statistical computations and analyses assume that the variables have a specific levels of measurement. For example, it would not make sense to compute an average hair color. An average of a categorical variable does not make much sense because there is no intrinsic ordering of the levels of the categories. Moreover, if you tried to compute the average of educational experience as defined in the ordinal section above, you would also obtain a nonsensical result. Because the spacing between the four levels of educational experience is very uneven, the meaning of this average would be very questionable. In short, an average requires a variable to be interval. Sometimes you have variables that are “in between” ordinal and interval, for example, a fivepoint likert scale with values “strongly agree”, “agree”, “neutral”, “disagree” and “strongly disagree”. If we cannot be sure that the intervals between each of these five values are the same, then we would not be able to say that this is an interval variable, but we would say that it is an ordinal variable. However, in order to be able to use statistics that assume the variable is interval, we will assume that the intervals are equally spaced.
Does it matter if my dependent variable is normally distributed?
When you are doing a ttest or ANOVA, the assumption is that the distribution of the sample means are normally distributed. One way to guarantee this is for the distribution of the individual observations from the sample to be normal. However, even if the distribution of the individual observations is not normal, the distribution of the sample means will be normally distributed if your sample size is about 30 or larger. This is due to the “central limit theorem” that shows that even when a population is nonnormally distributed, the distribution of the “sample means” will be normally distributed when the sample size is 30 or more, for example seeCentral limit theorem demonstration .
If you are doing a regression analysis, then the assumption is that your residuals are normally distributed. One way to make it very likely to have normal residuals is to have a dependent variable that is normally distributed and predictors that are all normally distributed, however this is not necessary for your residuals to be normally distributed. You can see Regression with SAS: Chapter 2 – Regression Diagnostics, Regression with SAS: Chapter 2 – Regression Diagnostics, or Regression with SAS: Chapter 2 – Regression Diagnostics
Means difference
Chisquare (Categorical data)
[youtube]http://www.youtube.com/watch?v=DBsMPZqJjo[/youtube]
ttest independent samples
[youtube]http://www.youtube.com/watch?v=by4c3h3WXQc[/youtube]
Analysis questionnaire (likert) – non parametric test using Chisquare test
[youtube]http://www.youtube.com/watch?v=B3jjm_AyMI[/youtube]
Number of Dependent Variables 
Nature of Independent Variables 
Test(s) 

1 
0 IVs (1 population) 
interval & normal 
onesample ttest 
ordinal or interval 
onesample median 

categorical (2 categories) 
binomial test 

categorical 
Chisquare goodnessoffit 

1 IV with 2 levels (independent groups) 
interval & normal 
2 independent sample ttest 

ordinal or interval 

WilcoxonMann Whitney test 

categorical 
Chi square test 

Fisher’s exact test 

1 IV with 2 or more levels (independent groups) 
interval & normal 
oneway ANOVA 

ordinal or interval 
Kruskal Wallis 

categorical 
Chi square test 

1 IV with 2 levels (dependent/matched groups) 
interval & normal 
paired ttest 

ordinal or interval 
Wilcoxon signed ranks test 

categorical 
McNemar 

1 IV with 2 or more levels (dependent/matched groups) 
interval & normal 
oneway repeated measures ANOVA 

ordinal or interval 
Friedman test 

categorical 
repeated measures logistic regression 

2 or more IVs (independent groups) 
interval & normal 
factorial ANOVA 

ordinal or interval 
ordered logistic regression 

categorical 
factorial logistic regression 

1 interval IV 
interval & normal 
correlation 

simple linear regression 

ordinal or interval 
nonparametric correlation 

categorical 
simple logistic regression 

1 or more interval IVs and/or 1 or more categorical IVs 
interval & normal 
multiple regression 

analysis of covariance 

categorical 
multiple logistic regression 

discriminant analysis 

2 or more 
1 IV with 2 or more levels (independent groups) 
interval & normal 
oneway MANOVA 
2 or more 
2 or more 
interval & normal 
multivariate multiple linear regression 
2 sets of 2 or more 
0 
interval & normal 
canonical correlation 
2 or more 
0 
interval & normal 
factor analysis 
Number of Dependent Variables 
Nature of Independent Variables 
Test(s) 
Source: http://www.ats.ucla.edu/stat/stata/whatstat/whatstat.htm#wilc
What statistical analysis should I use?
Statistical analyses using Stata
Version info: Code for this page was tested in Stata 12.
Introduction
This page shows how to perform a number of statistical tests using Stata. Each section gives a brief description of the aim of the statistical test, when it is used, an example showing the Stata commands and Stata output with a brief interpretation of the output. You can see the page Choosing the Correct Statistical Test for a table that shows an overview of when each test is appropriate to use. In deciding which test is appropriate to use, it is important to consider the type of variables that you have (i.e., whether your variables are categorical, ordinal or interval and whether they are normally distributed), see What is the difference between categorical, ordinal and interval variables? for more information on this.
About the hsb data file
Most of the examples in this page will use a data file called hsb2, high school and beyond. This data file contains 200 observations from a sample of high school students with demographic information about the students, such as their gender (female), socioeconomic status (ses) and ethnic background (race). It also contains a number of scores on standardized tests, including tests of reading (read), writing (write), mathematics (math) and social studies (socst). You can get the hsb2data file from within Stata by typing:
use http://www.ats.ucla.edu/stat/stata/notes/hsb2
One sample ttest
A one sample ttest allows us to test whether a sample mean (of a normally distributed interval variable) significantly differs from a hypothesized value. For example, using the hsb2 data file, say we wish to test whether the average writing score (write) differs significantly from 50. We can do this as shown below.
ttest write=50Onesample t test  Variable  Obs Mean Std. Err. Std. Dev. [95% Conf. Interval] + write  200 52.775 .6702372 9.478586 51.45332 54.09668  Degrees of freedom: 199 Ho: mean(write) = 50 Ha: mean < 50 Ha: mean ~= 50 Ha: mean > 50 t = 4.1403 t = 4.1403 t = 4.1403 P < t = 1.0000 P > t = 0.0001 P > t = 0.0000The mean of the variable write for this particular sample of students is 52.775, which is statistically significantly different from the test value of 50. We would conclude that this group of students has a significantly higher mean on the writing test than 50.
See also
One sample median test
A one sample median test allows us to test whether a sample median differs significantly from a hypothesized value. We will use the same variable, write, as we did in the one sample ttest example above, but we do not need to assume that it is interval and normally distributed (we only need to assume that write is an ordinal variable and that its distribution is symmetric). We will test whether the median writing score (write) differs significantly from 50.
signrank write=50Wilcoxon signedrank test sign  obs sum ranks expected + positive  126 13429 10048.5 negative  72 6668 10048.5 zero  2 3 3 + all  200 20100 20100 unadjusted variance 671675.00 adjustment for ties 1760.25 adjustment for zeros 1.25  adjusted variance 669913.50 Ho: write = 50 z = 4.130 Prob > z = 0.0000The results indicate that the median of the variable write for this group is statistically significantly different from 50.
See also
Binomial test
A one sample binomial test allows us to test whether the proportion of successes on a twolevel categorical dependent variable significantly differs from a hypothesized value. For example, using the hsb2 data file, say we wish to test whether the proportion of females (female) differs significantly from 50%, i.e., from .5. We can do this as shown below.
bitest female=.5Variable  N Observed k Expected k Assumed p Observed p + female  200 109 100 0.50000 0.54500 Pr(k >= 109) = 0.114623 (onesided test) Pr(k <= 109) = 0.910518 (onesided test) Pr(k <= 91 or k >= 109) = 0.229247 (twosided test)The results indicate that there is no statistically significant difference (p = .2292). In other words, the proportion of females does not significantly differ from the hypothesized value of 50%.
See also
Chisquare goodness of fit
A chisquare goodness of fit test allows us to test whether the observed proportions for a categorical variable differ from hypothesized proportions. For example, let’s suppose that we believe that the general population consists of 10% Hispanic, 10% Asian, 10% African American and 70% White folks. We want to test whether the observed proportions from our sample differ significantly from these hypothesized proportions. To conduct the chisquare goodness of fit test, you need to first download the csgof program that performs this test. You can download csgof from within Stata by typing findit csgof (seeHow can I used the findit command to search for programs and get additional help? for more information about using findit).
Now that the csgof program is installed, we can use it by typing:
csgof race, expperc(10 10 10 70) race expperc expfreq obsfreq hispanic 10 20 24 asian 10 20 11 africanamer 10 20 20 white 70 140 145 chisq(3) is 5.03, p = .1697These results show that racial composition in our sample does not differ significantly from the hypothesized values that we supplied (chisquare with three degrees of freedom = 5.03, p = .1697).
See also
Two independent samples ttest
An independent samples ttest is used when you want to compare the means of a normally distributed interval dependent variable for two independent groups. For example, using the hsb2 data file, say we wish to test whether the mean for write is the same for males and females.
ttest write, by(female) Twosample t test with equal variances  Group  Obs Mean Std. Err. Std. Dev. [95% Conf. Interval] + male  91 50.12088 1.080274 10.30516 47.97473 52.26703 female  109 54.99083 .7790686 8.133715 53.44658 56.53507 + combined  200 52.775 .6702372 9.478586 51.45332 54.09668 + diff  4.869947 1.304191 7.441835 2.298059  Degrees of freedom: 198 Ho: mean(male)  mean(female) = diff = 0 Ha: diff < 0 Ha: diff ~= 0 Ha: diff > 0 t = 3.7341 t = 3.7341 t = 3.7341 P < t = 0.0001 P > t = 0.0002 P > t = 0.9999The results indicate that there is a statistically significant difference between the mean writing score for males and females (t = 3.7341, p = .0002). In other words, females have a statistically significantly higher mean score on writing (54.99) than males (50.12).
See also
WilcoxonMannWhitney test
The WilcoxonMannWhitney test is a nonparametric analog to the independent samples ttest and can be used when you do not assume that the dependent variable is a normally distributed interval variable (you only assume that the variable is at least ordinal). You will notice that the Stata syntax for the WilcoxonMannWhitney test is almost identical to that of the independent samples ttest. We will use the same data file (the hsb2 data file) and the same variables in this example as we did in theindependent ttest example above and will not assume that write, our dependent variable, is normally distributed.
ranksum write, by(female)Twosample Wilcoxon ranksum (MannWhitney) test female  obs rank sum expected + male  91 7792 9145.5 female  109 12308 10954.5 + combined  200 20100 20100 unadjusted variance 166143.25 adjustment for ties 852.96  adjusted variance 165290.29 Ho: write(female==male) = write(female==female) z = 3.329 Prob > z = 0.0009The results suggest that there is a statistically significant difference between the underlying distributions of the write scores of males and the write scores of females (z = 3.329, p = 0.0009). You can determine which group has the higher rank by looking at the how the actual rank sums compare to the expected rank sums under the null hypothesis. The sum of the female ranks was higher while the sum of the male ranks was lower. Thus the female group had higher rank.
See also
Chisquare test
A chisquare test is used when you want to see if there is a relationship between two categorical variables. In Stata, the chi2option is used with the tabulate command to obtain the test statistic and its associated pvalue. Using the hsb2 data file, let’s see if there is a relationship between the type of school attended (schtyp) and students’ gender (female). Remember that the chisquare test assumes the expected value of each cell is five or higher. This assumption is easily met in the examples below. However, if this assumption is not met in your data, please see the section on Fisher’s exact test below.
tabulate schtyp female, chi2 type of  female school  male female  Total ++ public  77 91  168 private  14 18  32 ++ Total  91 109  200 Pearson chi2(1) = 0.0470 Pr = 0.828These results indicate that there is no statistically significant relationship between the type of school attended and gender (chisquare with one degree of freedom = 0.0470, p = 0.828).
Let’s look at another example, this time looking at the relationship between gender (female) and socioeconomic status (ses). The point of this example is that one (or both) variables may have more than two levels, and that the variables do not have to have the same number of levels. In this example, female has two levels (male and female) and ses has three levels (low, medium and high).
tabulate female ses, chi2  ses female  low middle high  Total ++ male  15 47 29  91 female  32 48 29  109 ++ Total  47 95 58  200 Pearson chi2(2) = 4.5765 Pr = 0.101Again we find that there is no statistically significant relationship between the variables (chisquare with two degrees of freedom = 4.5765, p = 0.101).
See also
Fisher’s exact test
The Fisher’s exact test is used when you want to conduct a chisquare test, but one or more of your cells has an expected frequency of five or less. Remember that the chisquare test assumes that each cell has an expected frequency of five or more, but the Fisher’s exact test has no such assumption and can be used regardless of how small the expected frequency is. In the example below, we have cells with observed frequencies of two and one, which may indicate expected frequencies that could be below five, so we will use Fisher’s exact test with the exact option on the tabulate command.
tabulate schtyp race, exact type of  race school  hispanic asian africana white  Total ++ public  22 10 18 118  168 private  2 1 2 27  32 ++ Total  24 11 20 145  200 Fisher's exact = 0.597These results suggest that there is not a statistically significant relationship between race and type of school (p = 0.597). Note that the Fisher’s exact test does not have a “test statistic”, but computes the pvalue directly.
See also
Oneway ANOVA
A oneway analysis of variance (ANOVA) is used when you have a categorical independent variable (with two or more categories) and a normally distributed interval dependent variable and you wish to test for differences in the means of the dependent variable broken down by the levels of the independent variable. For example, using the hsb2 data file, say we wish to test whether the mean of write differs between the three program types (prog). The command for this test would be:
anova write prog Number of obs = 200 Rsquared = 0.1776 Root MSE = 8.63918 Adj Rsquared = 0.1693 Source  Partial SS df MS F Prob > F + Model  3175.69786 2 1587.84893 21.27 0.0000  prog  3175.69786 2 1587.84893 21.27 0.0000  Residual  14703.1771 197 74.635417 + Total  17878.875 199 89.843593The mean of the dependent variable differs significantly among the levels of program type. However, we do not know if the difference is between only two of the levels or all three of the levels. (The F test for the Model is the same as the F test forprog because prog was the only variable entered into the model. If other variables had also been entered, the F test for theModel would have been different from prog.) To see the mean of write for each level of program type, you can use thetabulate command with the summarize option, as illustrated below.
tabulate prog, summarize(write) type of  Summary of writing score program  Mean Std. Dev. Freq. + general  51.333333 9.3977754 45 academic  56.257143 7.9433433 105 vocation  46.76 9.3187544 50 + Total  52.775 9.478586 200From this we can see that the students in the academic program have the highest mean writing score, while students in the vocational program have the lowest.
See also
Kruskal Wallis test
The Kruskal Wallis test is used when you have one independent variable with two or more levels and an ordinal dependent variable. In other words, it is the nonparametric version of ANOVA and a generalized form of the MannWhitney test method since it permits 2 or more groups. We will use the same data file as the one way ANOVA example above (the hsb2 data file) and the same variables as in the example above, but we will not assume that write is a normally distributed interval variable.
kwallis write, by(prog)Test: Equality of populations (KruskalWallis test) prog _Obs _RankSum general < 45 4079.00 academic 105 12764.00 vocation 50 3257.00 chisquared = 33.870 with 2 d.f. probability = 0.0001 chisquared with ties = 34.045 with 2 d.f. probability = 0.0001If some of the scores receive tied ranks, then a correction factor is used, yielding a slightly different value of chisquared. With or without ties, the results indicate that there is a statistically significant difference among the three type of programs.
Paired ttest
A paired (samples) ttest is used when you have two related observations (i.e. two observations per subject) and you want to see if the means on these two normally distributed interval variables differ from one another. For example, using the hsb2 data file we will test whether the mean of read is equal to the mean of write.
ttest read = writePaired t test  Variable  Obs Mean Std. Err. Std. Dev. [95% Conf. Interval] + read  200 52.23 .7249921 10.25294 50.80035 53.65965 write  200 52.775 .6702372 9.478586 51.45332 54.09668 + diff  200 .545 .6283822 8.886666 1.784142 .6941424  Ho: mean(read  write) = mean(diff) = 0 Ha: mean(diff) < 0 Ha: mean(diff) ~= 0 Ha: mean(diff) > 0 t = 0.8673 t = 0.8673 t = 0.8673 P < t = 0.1934 P > t = 0.3868 P > t = 0.8066These results indicate that the mean of read is not statistically significantly different from the mean of write (t = 0.8673, p = 0.3868).
See also
Wilcoxon signed rank sum test
The Wilcoxon signed rank sum test is the nonparametric version of a paired samples ttest. You use the Wilcoxon signed rank sum test when you do not wish to assume that the difference between the two variables is interval and normally distributed (but you do assume the difference is ordinal). We will use the same example as above, but we will not assume that the difference between read and write is interval and normally distributed.
signrank read = writeWilcoxon signedrank test sign  obs sum ranks expected + positive  88 9264 9990 negative  97 10716 9990 zero  15 120 120 + all  200 20100 20100 unadjusted variance 671675.00 adjustment for ties 715.25 adjustment for zeros 310.00  adjusted variance 670649.75 Ho: read = write z = 0.887 Prob > z = 0.3753The results suggest that there is not a statistically significant difference between read and write.
If you believe the differences between read and write were not ordinal but could merely be classified as positive and negative, then you may want to consider a sign test in lieu of sign rank test. Again, we will use the same variables in this example and assume that this difference is not ordinal.
signtest read = writeSign test sign  observed expected + positive  88 92.5 negative  97 92.5 zero  15 15 + all  200 200 Onesided tests: Ho: median of read  write = 0 vs. Ha: median of read  write > 0 Pr(#positive >= 88) = Binomial(n = 185, x >= 88, p = 0.5) = 0.7688 Ho: median of read  write = 0 vs. Ha: median of read  write < 0 Pr(#negative >= 97) = Binomial(n = 185, x >= 97, p = 0.5) = 0.2783 Twosided test: Ho: median of read  write = 0 vs. Ha: median of read  write ~= 0 Pr(#positive >= 97 or #negative >= 97) = min(1, 2*Binomial(n = 185, x >= 97, p = 0.5)) = 0.5565This output gives both of the onesided tests as well as the twosided test. Assuming that we were looking for any difference, we would use the twosided test and conclude that no statistically significant difference was found (p=.5565).
See also
McNemar test
You would perform McNemar’s test if you were interested in the marginal frequencies of two binary outcomes. These binary outcomes may be the same outcome variable on matched pairs (like a casecontrol study) or two outcome variables from a single group. For example, let us consider two questions, Q1 and Q2, from a test taken by 200 students. Suppose 172 students answered both questions correctly, 15 students answered both questions incorrectly, 7 answered Q1 correctly and Q2 incorrectly, and 6 answered Q2 correctly and Q1 incorrectly. These counts can be considered in a twoway contingency table. The null hypothesis is that the two questions are answered correctly or incorrectly at the same rate (or that the contingency table is symmetric). We can enter these counts into Stata using mcci, a command from Stata’s epidemiology tables. The outcome is labeled according to casecontrol study conventions.
mcci 172 6 7 15 Controls  Cases  Exposed Unexposed  Total ++ Exposed  172 6  178 Unexposed  7 15  22 ++ Total  179 21  200 McNemar's chi2(1) = 0.08 Prob > chi2 = 0.7815 Exact McNemar significance probability = 1.0000 Proportion with factor Cases .89 Controls .895 [95% Conf. Interval]   difference .005 .045327 .035327 ratio .9944134 .9558139 1.034572 rel. diff. .047619 .39205 .2968119 odds ratio .8571429 .2379799 2.978588 (exact)McNemar’s chisquare statistic suggests that there is not a statistically significant difference in the proportions of correct/incorrect answers to these two questions.
Oneway repeated measures ANOVA
You would perform a oneway repeated measures analysis of variance if you had one categorical independent variable and a normally distributed interval dependent variable that was repeated at least twice for each subject. This is the equivalent of the paired samples ttest, but allows for two or more levels of the categorical variable. This tests whether the mean of the dependent variable differs by the categorical variable. We have an example data set called rb4, which is used in Kirk’s book Experimental Design. In this data set, y is the dependent variable, a is the repeated measure and s is the variable that indicates the subject number.
use http://www.ats.ucla.edu/stat/stata/examples/kirk/rb4 anova y a s, repeated(a)Number of obs = 32 Rsquared = 0.7318 Root MSE = 1.18523 Adj Rsquared = 0.6041 Source  Partial SS df MS F Prob > F + Model  80.50 10 8.05 5.73 0.0004  a  49.00 3 16.3333333 11.63 0.0001 s  31.50 7 4.50 3.20 0.0180  Residual  29.50 21 1.4047619 + Total  110.00 31 3.5483871 Betweensubjects error term: s Levels: 8 (7 df) Lowest b.s.e. variable: s Repeated variable: a HuynhFeldt epsilon = 0.8343 GreenhouseGeisser epsilon = 0.6195 Box's conservative epsilon = 0.3333  Prob > F  Source  df F Regular HF GG Box + a  3 11.63 0.0001 0.0003 0.0015 0.0113 Residual  21 +You will notice that this output gives four different pvalues. The “regular” (0.0001) is the pvalue that you would get if you assumed compound symmetry in the variancecovariance matrix. Because that assumption is often not valid, the three other pvalues offer various corrections (the HuynhFeldt, HF, GreenhouseGeisser, GG and Box’s conservative, Box). No matter which pvalue you use, our results indicate that we have a statistically significant effect of a at the .05 level.
See also
Repeated measures logistic regression
If you have a binary outcome measured repeatedly for each subject and you wish to run a logistic regression that accounts for the effect of these multiple measures from each subjects, you can perform a repeated measures logistic regression. In Stata, this can be done using the xtgee command and indicating binomial as the probability distribution and logit as the link function to be used in the model. The exercise data file contains 3 pulse measurements of 30 people assigned to 2 different diet regiments and 3 different exercise regiments. If we define a “high” pulse as being over 100, we can then predict the probability of a high pulse using diet regiment.
First, we use xtset to define which variable defines the repetitions. In this dataset, there are three measurements taken for each id, so we will use id as our panel variable. Then we can use i: before diet so that we can create indicator variables as needed.
use http://www.ats.ucla.edu/stat/stata/whatstat/exercise, clear xtset id xtgee highpulse i.diet, family(binomial) link(logit)Iteration 1: tolerance = 1.753e08 GEE populationaveraged model Number of obs = 90 Group variable: id Number of groups = 30 Link: logit Obs per group: min = 3 Family: binomial avg = 3.0 Correlation: exchangeable max = 3 Wald chi2(1) = 1.53 Scale parameter: 1 Prob > chi2 = 0.2157  highpulse  Coef. Std. Err. z P>z [95% Conf. Interval] + 2.diet  .7537718 .6088196 1.24 0.216 .4394927 1.947036 _cons  1.252763 .4621704 2.71 0.007 2.1586 .3469257 These results indicate that diet is not statistically significant (Z = 1.24, p = 0.216).
Factorial ANOVA
A factorial ANOVA has two or more categorical independent variables (either with or without the interactions) and a single normally distributed interval dependent variable. For example, using the hsb2 data file we will look at writing scores (write) as the dependent variable and gender (female) and socioeconomic status (ses) as independent variables, and we will include an interaction of female by ses. Note that in Stata, you do not need to have the interaction term(s) in your data set. Rather, you can have Stata create it/them temporarily by placing an asterisk between the variables that will make up the interaction term(s).
anova write female ses female##ses Number of obs = 200 Rsquared = 0.1274 Root MSE = 8.96748 Adj Rsquared = 0.1049 Source  Partial SS df MS F Prob > F + Model  2278.24419 5 455.648837 5.67 0.0001  female  1334.49331 1 1334.49331 16.59 0.0001 ses  1063.2527 2 531.626349 6.61 0.0017 female#ses  21.4309044 2 10.7154522 0.13 0.8753  Residual  15600.6308 194 80.4156228 + Total  17878.875 199 89.843593These results indicate that the overall model is statistically significant (F = 5.67, p = 0.001). The variables female and ses are also statistically significant (F = 16.59, p = 0.0001 and F = 6.61, p = 0.0017, respectively). However, that interaction betweenfemale and ses is not statistically significant (F = 0.13, p = 0.8753).
See also
Friedman test
You perform a Friedman test when you have one withinsubjects independent variable with two or more levels and a dependent variable that is not interval and normally distributed (but at least ordinal). We will use this test to determine if there is a difference in the reading, writing and math scores. The null hypothesis in this test is that the distribution of the ranks of each type of score (i.e., reading, writing and math) are the same. To conduct the Friedman test in Stata, you need to first download the friedman program that performs this test. You can download friedman from within Stata by typing findit friedman (see How can I used the findit command to search for programs and get additional help? for more information about using findit). Also, your data will need to be transposed such that subjects are the columns and the variables are the rows. We will use the xpose command to arrange our data this way.
use http://www.ats.ucla.edu/stat/stata/notes/hsb2 keep read write math xpose, clear friedman v1v200Friedman = 0.6175 Kendall = 0.0015 Pvalue = 0.7344Friedman’s chisquare has a value of 0.6175 and a pvalue of 0.7344 and is not statistically significant. Hence, there is no evidence that the distributions of the three types of scores are different.
Ordered logistic regression
Ordered logistic regression is used when the dependent variable is ordered, but not continuous. For example, using the hsb2 data file we will create an ordered variable called write3. This variable will have the values 1, 2 and 3, indicating a low, medium or high writing score. We do not generally recommend categorizing a continuous variable in this way; we are simply creating a variable to use for this example. We will use gender (female), reading score (read) and social studies score (socst) as predictor variables in this model.
use http://www.ats.ucla.edu/stat/stata/notes/hsb2 generate write3 = 1 replace write3 = 2 if write >= 49 & write <= 57 replace write3 = 3 if write >= 58 & write <= 70ologit write3 female read socst Iteration 0: log likelihood = 218.31357 Iteration 1: log likelihood = 157.692 Iteration 2: log likelihood = 156.28133 Iteration 3: log likelihood = 156.27632 Iteration 4: log likelihood = 156.27632 Ordered logistic regression Number of obs = 200 LR chi2(3) = 124.07 Prob > chi2 = 0.0000 Log likelihood = 156.27632 Pseudo R2 = 0.2842  write3  Coef. Std. Err. z P>z [95% Conf. Interval] + female  1.285435 .3244567 3.96 0.000 .6495115 1.921359 read  .1177202 .0213565 5.51 0.000 .0758623 .1595781 socst  .0801873 .0194432 4.12 0.000 .0420794 .1182952 + /cut1  9.703706 1.197002 7.357626 12.04979 /cut2  11.8001 1.304306 9.243705 14.35649 The results indicate that the overall model is statistically significant (p < .0000), as are each of the predictor variables (p < .000). There are two cutpoints for this model because there are three levels of the outcome variable.
One of the assumptions underlying ordinal logistic (and ordinal probit) regression is that the relationship between each pair of outcome groups is the same. In other words, ordinal logistic regression assumes that the coefficients that describe the relationship between, say, the lowest versus all higher categories of the response variable are the same as those that describe the relationship between the next lowest category and all higher categories, etc. This is called the proportional odds assumption or the parallel regression assumption. Because the relationship between all pairs of groups is the same, there is only one set of coefficients (only one model). If this was not the case, we would need different models (such as a generalized ordered logit model) to describe the relationship between each pair of outcome groups. To test this assumption, we can use either the omodel command (findit omodel, see How can I used the findit command to search for programs and get additional help? for more information about using findit) or the brant command. We will show both below.
omodel logit write3 female read socst Iteration 0: log likelihood = 218.31357 Iteration 1: log likelihood = 158.87444 Iteration 2: log likelihood = 156.35529 Iteration 3: log likelihood = 156.27644 Iteration 4: log likelihood = 156.27632 Ordered logit estimates Number of obs = 200 LR chi2(3) = 124.07 Prob > chi2 = 0.0000 Log likelihood = 156.27632 Pseudo R2 = 0.2842  write3  Coef. Std. Err. z P>z [95% Conf. Interval] + female  1.285435 .3244565 3.96 0.000 .649512 1.921358 read  .1177202 .0213564 5.51 0.000 .0758623 .159578 socst  .0801873 .0194432 4.12 0.000 .0420794 .1182952 + _cut1  9.703706 1.197 (Ancillary parameters) _cut2  11.8001 1.304304  Approximate likelihoodratio test of proportionality of odds across response categories: chi2(3) = 2.03 Prob > chi2 = 0.5658 brant, detail Estimated coefficients from j1 binary regressions y>1 y>2 female 1.5673604 1.0629714 read .11712422 .13401723 socst .0842684 .06429241 _cons 10.001584 11.671854 Brant Test of Parallel Regression Assumption Variable  chi2 p>chi2 df + All  2.07 0.558 3 + female  1.08 0.300 1 read  0.26 0.608 1 socst  0.52 0.470 1  A significant test statistic provides evidence that the parallel regression assumption has been violated.Both of these tests indicate that the proportional odds assumption has not been violated.
See also
Factorial logistic regression
A factorial logistic regression is used when you have two or more categorical independent variables but a dichotomous dependent variable. For example, using the hsb2 data file we will use female as our dependent variable, because it is the only dichotomous (0/1) variable in our data set; certainly not because it common practice to use gender as an outcome variable. We will use type of program (prog) and school type (schtyp) as our predictor variables. Because prog is a categorical variable (it has three levels), we need to create dummy codes for it. The use of i.prog does this. You can use the logitcommand if you want to see the regression coefficients or the logistic command if you want to see the odds ratios.
logit female i.prog##schtyp Iteration 0: log likelihood = 137.81834 Iteration 1: log likelihood = 136.25886 Iteration 2: log likelihood = 136.24502 Iteration 3: log likelihood = 136.24501 Logistic regression Number of obs = 200 LR chi2(5) = 3.15 Prob > chi2 = 0.6774 Log likelihood = 136.24501 Pseudo R2 = 0.0114  female  Coef. Std. Err. z P>z [95% Conf. Interval] + prog  2  .3245866 .3910782 0.83 0.407 .4419125 1.091086 3  .2183474 .4319116 0.51 0.613 .6281839 1.064879  2.schtyp  1.660724 1.141326 1.46 0.146 .5762344 3.897683  prog#schtyp  2 2  1.934018 1.232722 1.57 0.117 4.350108 .4820729 3 2  1.827778 1.840256 0.99 0.321 5.434614 1.779057  _cons  .0512933 .3203616 0.16 0.873 .6791906 .576604 The results indicate that the overall model is not statistically significant (LR chi2 = 3.15, p = 0.6774). Furthermore, none of the coefficients are statistically significant either. We can use the test command to get the test of the overall effect of prog as shown below. This shows that the overall effect of prog is not statistically significant.
test 2.prog 3.prog ( 1) [female]2.prog = 0 ( 2) [female]3.prog = 0 chi2( 2) = 0.69 Prob > chi2 = 0.7086Likewise, we can use the testparm command to get the test of the overall effect of the prog by schtyp interaction, as shown below. This shows that the overall effect of this interaction is not statistically significant.
testparm prog#schtyp ( 1) [female]2.prog#2.schtyp = 0 ( 2) [female]3.prog#2.schtyp = 0 chi2( 2) = 2.47 Prob > chi2 = 0.2902If you prefer, you could use the logistic command to see the results as odds ratios, as shown below.
logistic female i.prog##schtyp Logistic regression Number of obs = 200 LR chi2(5) = 3.15 Prob > chi2 = 0.6774 Log likelihood = 136.24501 Pseudo R2 = 0.0114  female  Odds Ratio Std. Err. z P>z [95% Conf. Interval] + prog  2  1.383459 .5410405 0.83 0.407 .6428059 2.977505 3  1.244019 .5373063 0.51 0.613 .5335599 2.900487  2.schtyp  5.263121 6.006939 1.46 0.146 .5620107 49.28811  prog#schtyp  2 2  .1445662 .1782099 1.57 0.117 .0129054 1.619428 3 2  .1607704 .2958586 0.99 0.321 .0043629 5.924268 
Correlation
A correlation is useful when you want to see the linear relationship between two (or more) normally distributed interval variables. For example, using the hsb2 data file we can run a correlation between two continuous variables, read and write.
corr read write(obs=200)  read write + read  1.0000 write  0.5968 1.0000In the second example, we will run a correlation between a dichotomous variable, female, and a continuous variable, write. Although it is assumed that the variables are interval and normally distributed, we can include dummy variables when performing correlations.
corr female write(obs=200)  female write + female  1.0000 write  0.2565 1.0000In the first example above, we see that the correlation between read and write is 0.5968. By squaring the correlation and then multiplying by 100, you can determine what percentage of the variability is shared. Let’s round 0.5968 to be 0.6, which when squared would be .36, multiplied by 100 would be 36%. Hence read shares about 36% of its variability with write. In the output for the second example, we can see the correlation between write and female is 0.2565. Squaring this number yields .06579225, meaning that female shares approximately 6.5% of its variability with write.
See also
Simple linear regression
Simple linear regression allows us to look at the linear relationship between one normally distributed interval predictor and one normally distributed interval outcome variable. For example, using the hsb2 data file, say we wish to look at the relationship between writing scores (write) and reading scores (read); in other words, predicting write from read.
regress write read  write  Coef. Std. Err. t P>t [95% Conf. Interval] + read  .5517051 .0527178 10.47 0.000 .4477446 .6556656 _cons  23.95944 2.805744 8.54 0.000 18.42647 29.49242 We see that the relationship between write and read is positive (.5517051) and based on the tvalue (10.47) and pvalue (0.000), we would conclude this relationship is statistically significant. Hence, we would say there is a statistically significant positive linear relationship between reading and writing.
See also
 Regression With Stata: Chapter 1 – Simple and Multiple Regression
 Stata Annotated Output: Regression
 Stata Frequently Asked Questions
 Stata Topics: Regression
 Stata Textbook Example: Introduction to the Practice of Statistics, Chapter 10
 Stata Textbook Examples: Regression with Graphics, Chapter 2
 Stata Textbook Examples: Applied Regression Analysis, Chapter 5
Nonparametric correlation
A Spearman correlation is used when one or both of the variables are not assumed to be normally distributed and interval (but are assumed to be ordinal). The values of the variables are converted in ranks and then correlated. In our example, we will look for a relationship between read and write. We will not assume that both of these variables are normal and interval .
spearman read writeNumber of obs = 200 Spearman's rho = 0.6167 Test of Ho: read and write are independent Prob > t = 0.0000The results suggest that the relationship between read and write (rho = 0.6167, p = 0.000) is statistically significant.
Simple logistic regression
Logistic regression assumes that the outcome variable is binary (i.e., coded as 0 and 1). We have only one variable in thehsb2 data file that is coded 0 and 1, and that is female. We understand that female is a silly outcome variable (it would make more sense to use it as a predictor variable), but we can use female as the outcome variable to illustrate how the code for this command is structured and how to interpret the output. The first variable listed after the logistic (or logit) command is the outcome (or dependent) variable, and all of the rest of the variables are predictor (or independent) variables. You can use thelogit command if you want to see the regression coefficients or the logistic command if you want to see the odds ratios. In our example, female will be the outcome variable, and read will be the predictor variable. As with OLS regression, the predictor variables must be either dichotomous or continuous; they cannot be categorical.
logistic female read Logit estimates Number of obs = 200 LR chi2(1) = 0.56 Prob > chi2 = 0.4527 Log likelihood = 137.53641 Pseudo R2 = 0.0020  female  Odds Ratio Std. Err. z P>z [95% Conf. Interval] + read  .9896176 .0137732 0.75 0.453 .9629875 1.016984  logit female readIteration 0: log likelihood = 137.81834 Iteration 1: log likelihood = 137.53642 Iteration 2: log likelihood = 137.53641 Logit estimates Number of obs = 200 LR chi2(1) = 0.56 Prob > chi2 = 0.4527 Log likelihood = 137.53641 Pseudo R2 = 0.0020  female  Coef. Std. Err. z P>z [95% Conf. Interval] + read  .0104367 .0139177 0.75 0.453 .0377148 .0168415 _cons  .7260875 .7419612 0.98 0.328 .7281297 2.180305 The results indicate that reading score (read) is not a statistically significant predictor of gender (i.e., being female), z = 0.75, p = 0.453. Likewise, the test of the overall model is not statistically significant, LR chisquared 0.56, p = 0.4527.
See also
 Stata Textbook Examples: Applied Logistic Regression (2nd Ed) Chapter 1
 Stata Web Books: Logistic Regression in Stata
 Stata Topics: Logistic Regression
 Stata Data Analysis Example: Logistic Regression
 Annotated Stata Output: Logistic Regression Analysis
 Stata FAQ: How do I interpret odds ratios in logistic regression?
 Stata Library
 Teaching Tools: Graph Logistic Regression Curve
Multiple regression
Multiple regression is very similar to simple regression, except that in multiple regression you have more than one predictor variable in the equation. For example, using the hsb2 data file we will predict writing score from gender (female), reading, math, science and social studies (socst) scores.
regress write female read math science socstSource  SS df MS Number of obs = 200 + F( 5, 194) = 58.60 Model  10756.9244 5 2151.38488 Prob > F = 0.0000 Residual  7121.9506 194 36.7110855 Rsquared = 0.6017 + Adj Rsquared = 0.5914 Total  17878.875 199 89.843593 Root MSE = 6.059  write  Coef. Std. Err. t P>t [95% Conf. Interval] + female  5.492502 .8754227 6.27 0.000 3.765935 7.21907 read  .1254123 .0649598 1.93 0.055 .0027059 .2535304 math  .2380748 .0671266 3.55 0.000 .1056832 .3704665 science  .2419382 .0606997 3.99 0.000 .1222221 .3616542 socst  .2292644 .0528361 4.34 0.000 .1250575 .3334713 _cons  6.138759 2.808423 2.19 0.030 .599798 11.67772 The results indicate that the overall model is statistically significant (F = 58.60, p = 0.0000). Furthermore, all of the predictor variables are statistically significant except for read.
See also
 Regression with Stata: Lesson 1 – Simple and Multiple Regression
 Annotated Output: Multiple Linear Regression
 Stata Annotated Output: Regression
 Stata Teaching Tools
 Stata Textbook Examples: Applied Linear Statistical Models
 Stata Textbook Examples: Introduction to the Practice of Statistics, Chapter 11
 Stata Textbook Examples: Regression Analysis by Example, Chapter 3
Analysis of covariance
Analysis of covariance is like ANOVA, except in addition to the categorical predictors you also have continuous predictors as well. For example, the one way ANOVA example used write as the dependent variable and prog as the independent variable. Let’s add read as a continuous variable to this model, as shown below.
anova write prog c.read Number of obs = 200 Rsquared = 0.3925 Root MSE = 7.44408 Adj Rsquared = 0.3832 Source  Partial SS df MS F Prob > F + Model  7017.68123 3 2339.22708 42.21 0.0000  prog  650.259965 2 325.129983 5.87 0.0034 read  3841.98338 1 3841.98338 69.33 0.0000  Residual  10861.1938 196 55.4142539 + Total  17878.875 199 89.843593The results indicate that even after adjusting for reading score (read), writing scores still significantly differ by program type (prog) F = 5.87, p = 0.0034.
See also
Multiple logistic regression
Multiple logistic regression is like simple logistic regression, except that there are two or more predictors. The predictors can be interval variables or dummy variables, but cannot be categorical variables. If you have categorical predictors, they should be coded into one or more dummy variables. We have only one variable in our data set that is coded 0 and 1, and that isfemale. We understand that female is a silly outcome variable (it would make more sense to use it as a predictor variable), but we can use female as the outcome variable to illustrate how the code for this command is structured and how to interpret the output. The first variable listed after the logistic (or logit) command is the outcome (or dependent) variable, and all of the rest of the variables are predictor (or independent) variables. You can use the logit command if you want to see the regression coefficients or the logistic command if you want to see the odds ratios. In our example, female will be the outcome variable, and read and write will be the predictor variables.
logistic female read write Logit estimates Number of obs = 200 LR chi2(2) = 27.82 Prob > chi2 = 0.0000 Log likelihood = 123.90902 Pseudo R2 = 0.1009  female  Odds Ratio Std. Err. z P>z [95% Conf. Interval] + read  .9314488 .0182578 3.62 0.000 .8963428 .9679298 write  1.112231 .0246282 4.80 0.000 1.064993 1.161564 These results show that both read and write are significant predictors of female.
See also
 Stata Annotated Output: Logistic Regression
 Stata Library
 Stata Web Books: Logistic Regression with Stata
 Stata Topics: Logistic Regression
 Stata Textbook Examples: Applied Logistic Regression, Chapter 2
 Stata Textbook Examples: Applied Regression Analysis, Chapter 8
 Stata Textbook Examples: Introduction to Categorical Analysis, Chapter 5
 Stata Textbook Examples: Regression Analysis by Example, Chapter 12
Discriminant analysis
Discriminant analysis is used when you have one or more normally distributed interval independent variables and a categorical dependent variable. It is a multivariate technique that considers the latent dimensions in the independent variables for predicting group membership in the categorical dependent variable. For example, using the hsb2 data file, say we wish to useread, write and math scores to predict the type of program a student belongs to (prog). For this analysis, you need to first download the daoneway program that performs this test. You can download daoneway from within Stata by typing findit daoneway (see How can I used the findit command to search for programs and get additional help? for more information about using findit).
You can then perform the discriminant function analysis like this.
daoneway read write math, by(prog)Oneway Disciminant Function Analysis Observations = 200 Variables = 3 Groups = 3 Pct of Cum Canonical After Wilks' Fcn Eigenvalue Variance Pct Corr Fcn Lambda Chisquare df Pvalue  0 0.73398 60.619 6 0.0000 1 0.3563 98.74 98.74 0.5125  1 0.99548 0.888 2 0.6414 2 0.0045 1.26 100.00 0.0672  Unstandardized canonical discriminant function coefficients func1 func2 read 0.0292 0.0439 write 0.0383 0.1370 math 0.0703 0.0793 _cons 7.2509 0.7635 Standardized canonical discriminant function coefficients func1 func2 read 0.2729 0.4098 write 0.3311 1.1834 math 0.5816 0.6557 Canonical discriminant structure matrix func1 func2 read 0.7785 0.1841 write 0.7753 0.6303 math 0.9129 0.2725 Group means on canonical discriminant functions func1 func2 prog1 0.3120 0.1190 prog2 0.5359 0.0197 prog3 0.8445 0.0658Clearly, the Stata output for this procedure is lengthy, and it is beyond the scope of this page to explain all of it. However, the main point is that two canonical variables are identified by the analysis, the first of which seems to be more related to program type than the second. For more information, see this page on discriminant function analysis.
See also
Oneway MANOVA
MANOVA (multivariate analysis of variance) is like ANOVA, except that there are two or more dependent variables. In a oneway MANOVA, there is one categorical independent variable and two or more dependent variables. For example, using thehsb2 data file, say we wish to examine the differences in read, write and math broken down by program type (prog). For this analysis, you can use the manova command and then perform the analysis like this.
manova read write math = prog, category(prog)Number of obs = 200 W = Wilks' lambda L = LawleyHotelling trace P = Pillai's trace R = Roy's largest root Source  Statistic df F(df1, df2) = F Prob>F + prog  W 0.7340 2 6.0 390.0 10.87 0.0000 e  P 0.2672 6.0 392.0 10.08 0.0000 a  L 0.3608 6.0 388.0 11.67 0.0000 a  R 0.3563 3.0 196.0 23.28 0.0000 u  Residual  197 + Total  199  e = exact, a = approximate, u = upper bound on FThis command produces three different test statistics that are used to evaluate the statistical significance of the relationship between the independent variable and the outcome variables. According to all three criteria, the students in the different programs differ in their joint distribution of read, write and math.
See also
 Stata Data Analysis Examples: Oneway MANOVA
 Stata Annotated Output: Oneway MANOVA
 Stata FAQ: How can I do multivariate repeated measures in Stata?
Multivariate multiple regression
Multivariate multiple regression is used when you have two or more dependent variables that are to be predicted from two or more predictor variables. In our example, we will predict write and read from female, math, science and social studies (socst) scores.
mvreg write read = female math science socstEquation Obs Parms RMSE "Rsq" F P  write 200 5 6.101191 0.5940 71.32457 0.0000 read 200 5 6.679383 0.5841 68.4741 0.0000   Coef. Std. Err. t P>t [95% Conf. Interval] + write  female  5.428215 .8808853 6.16 0.000 3.69093 7.165501 math  .2801611 .0639308 4.38 0.000 .1540766 .4062456 science  .2786543 .0580452 4.80 0.000 .1641773 .3931313 socst  .2681117 .049195 5.45 0.000 .1710892 .3651343 _cons  6.568924 2.819079 2.33 0.021 1.009124 12.12872 + read  female  .512606 .9643644 0.53 0.596 2.414529 1.389317 math  .3355829 .0699893 4.79 0.000 .1975497 .4736161 science  .2927632 .063546 4.61 0.000 .1674376 .4180889 socst  .3097572 .0538571 5.75 0.000 .2035401 .4159744 _cons  3.430005 3.086236 1.11 0.268 2.656682 9.516691 Many researchers familiar with traditional multivariate analysis may not recognize the tests above. They do not see Wilks’ Lambda, Pillai’s Trace or the HotellingLawley Trace statistics, the statistics with which they are familiar. It is possible to obtain these statistics using the mvtest command written by David E. Moore of the University of Cincinnati. UCLA updated this command to work with Stata 6 and above. You can download mvtest from within Stata by typing findit mvtest (see How can I used the findit command to search for programs and get additional help? for more information about using findit).
Now that we have downloaded it, we can use the command shown below.
mvtest femaleMULTIVARIATE TESTS OF SIGNIFICANCE Multivariate Test Criteria and Exact F Statistics for the Hypothesis of no Overall "female" Effect(s) S=1 M=0 N=96 Test Value F Num DF Den DF Pr > F Wilks' Lambda 0.83011470 19.8513 2 194.0000 0.0000 Pillai's Trace 0.16988530 19.8513 2 194.0000 0.0000 HotellingLawley Trace 0.20465280 19.8513 2 194.0000 0.0000These results show that female has a significant relationship with the joint distribution of write and read. The mvtestcommand could then be repeated for each of the other predictor variables.
See also
Canonical correlation
Canonical correlation is a multivariate technique used to examine the relationship between two groups of variables. For each set of variables, it creates latent variables and looks at the relationships among the latent variables. It assumes that all variables in the model are interval and normally distributed. Stata requires that each of the two groups of variables be enclosed in parentheses. There need not be an equal number of variables in the two groups.
canon (read write) (math science) Linear combinations for canonical correlation 1 Number of obs = 200   Coef. Std. Err. t P>t [95% Conf. Interval] + u  read  .0632613 .007111 8.90 0.000 .0492386 .077284 write  .0492492 .007692 6.40 0.000 .0340809 .0644174 + v  math  .0669827 .0080473 8.32 0.000 .0511138 .0828515 science  .0482406 .0076145 6.34 0.000 .0332252 .0632561  (Std. Errors estimated conditionally) Canonical correlations: 0.7728 0.0235The output above shows the linear combinations corresponding to the first canonical correlation. At the bottom of the output are the two canonical correlations. These results indicate that the first canonical correlation is .7728. You will note that Stata is brief and may not provide you with all of the information that you may want. Several programs have been developed to provide more information regarding the analysis. You can download this family of programs by typing findit cancor (see How can I used the findit command to search for programs and get additional help? for more information about using findit).
Because the output from the cancor command is lengthy, we will use the cantest command to obtain the eigenvalues, Ftests and associated pvalues that we want. Note that you do not have to specify a model with either the cancor or the cantestcommands if they are issued after the canon command.
cantestCanon Can Corr Likelihood Approx Corr Squared Ratio F df1 df2 Pr > F 7728 .59728 0.4025 56.4706 4 392.000 0.0000 0235 .00055 0.9994 0.1087 1 197.000 0.7420 Eigenvalue Proportion Cumulative 1.4831 0.9996 0.9996 0.0006 0.0004 1.0000The Ftest in this output tests the hypothesis that the first canonical correlation is equal to zero. Clearly, F = 56.4706 is statistically significant. However, the second canonical correlation of .0235 is not statistically significantly different from zero (F = 0.1087, p = 0.7420).
See also
Factor analysis
Factor analysis is a form of exploratory multivariate analysis that is used to either reduce the number of variables in a model or to detect relationships among variables. All variables involved in the factor analysis need to be continuous and are assumed to be normally distributed. The goal of the analysis is to try to identify factors which underlie the variables. There may be fewer factors than variables, but there may not be more factors than variables. For our example, let’s suppose that we think that there are some common factors underlying the various test scores. We will first use the principal components method of extraction (by using the pc option) and then the principal components factor method of extraction (by using the pcf option). This parallels the output produced by SAS and SPSS.
factor read write math science socst, pc (obs=200) (principal components; 5 components retained) Component Eigenvalue Difference Proportion Cumulative  1 3.38082 2.82344 0.6762 0.6762 2 0.55738 0.15059 0.1115 0.7876 3 0.40679 0.05062 0.0814 0.8690 4 0.35617 0.05733 0.0712 0.9402 5 0.29884 . 0.0598 1.0000 Eigenvectors Variable  1 2 3 4 5 + read  0.46642 0.02728 0.53127 0.02058 0.70642 write  0.44839 0.20755 0.80642 0.05575 0.32007 math  0.45878 0.26090 0.00060 0.78004 0.33615 science  0.43558 0.61089 0.00695 0.58948 0.29924 socst  0.42567 0.71758 0.25958 0.20132 0.44269Now let’s rerun the factor analysis with a principal component factors extraction method and retain factors with eigenvalues of .5 or greater. Then we will use a varimax rotation on the solution.
factor read write math science socst, pcf mineigen(.5) (obs=200) (principal component factors; 2 factors retained) Factor Eigenvalue Difference Proportion Cumulative  1 3.38082 2.82344 0.6762 0.6762 2 0.55738 0.15059 0.1115 0.7876 3 0.40679 0.05062 0.0814 0.8690 4 0.35617 0.05733 0.0712 0.9402 5 0.29884 . 0.0598 1.0000 Factor Loadings Variable  1 2 Uniqueness + read  0.85760 0.02037 0.26410 write  0.82445 0.15495 0.29627 math  0.84355 0.19478 0.25048 science  0.80091 0.45608 0.15054 socst  0.78268 0.53573 0.10041rotate, varimax (varimax rotation) Rotated Factor Loadings Variable  1 2 Uniqueness + read  0.64808 0.56204 0.26410 write  0.50558 0.66942 0.29627 math  0.75506 0.42357 0.25048 science  0.89934 0.20159 0.15054 socst  0.21844 0.92297 0.10041Note that by default, Stata will retain all factors with positive eigenvalues; hence the use of the mineigen option or thefactors(#) option. The factors(#) option does not specify the number of solutions to retain, but rather the largest number of solutions to retain. From the table of factor loadings, we can see that all five of the test scores load onto the first factor, while all five tend to load not so heavily on the second factor. Uniqueness (which is the opposite of commonality) is the proportion of variance of the variable (i.e., read) that is not accounted for by all of the factors taken together, and a very high uniqueness can indicate that a variable may not belong with any of the factors. Factor loadings are often rotated in an attempt to make them more interpretable. Stata performs both varimax and promax rotations.
rotate, varimax(varimax rotation) Rotated Factor Loadings Variable  1 2 Uniqueness + read  0.62238 0.51992 0.34233 write  0.53933 0.54228 0.41505 math  0.65110 0.45408 0.36988 science  0.64835 0.37324 0.44033 socst  0.44265 0.58091 0.46660The purpose of rotating the factors is to get the variables to load either very high or very low on each factor. In this example, because all of the variables loaded onto factor 1 and not on factor 2, the rotation did not aid in the interpretation. Instead, it made the results even more difficult to interpret.
To obtain a scree plot of the eigenvalues, you can use the greigen command. We have included a reference line on the yaxis at one to aid in determining how many factors should be retained.
greigen, yline(1)See also
Perbedaan logit dan probit
http://home.gwu.edu/~soyer/mv1h.pdf
http://psfaculty.ucdavis.edu/bsjjones/binaryresponse.pdf
Probit
http://www.ats.ucla.edu/stat/stata/dae/probit.htm
Marginal effect in Probit
http://www.stata.com/support/faqs/statistics/marginaleffectsmethods/
http://www.stata.com/meeting/italy10/drukker_sug.pdf
Example by Green
http://www.ats.ucla.edu/stat/stata/examples/greene/greene19.htm
Source: http://www.csulb.edu/~cdennis/STATAEXCEL.doc
Getting Started:
1. Go to Stata prompt and click on “Intercooled Stata”
2. In the command line type: set mem 5000k (then press “enter”)
Note: for very large files: set mem 500000k (press “enter”)
then type: set matsize 150 (press “enter” – allows 150 variables)
3. Click on “file” (upper left corner)
4. Click on “open”
5. Click on “down arrow” to use either the “c” or “a” drives
6. Click so that the desired drive reveals its files
7. Click on the file you want to load
8. To execute an operation (e.g., ordered probit) type the following in the
command line: regress (now click on the variable names as listed on the left side of page beginning with the dependent variable – note that using that replacing regress with “fit” will deliver many useful diagnostics – in regression and dichotomous logit/probit a constant is automatically included). Then press “enter.” Other estimators: logit (for the odds ratio – instead of the log of the odds ratio that logit yields – replace logit with logistic), probit (for marginal effects replace probit with dprobit), oprobit, ologit (ordered probit/logit), mlogit (multinomial logit), nlogit (nested logit) and tobit. If using tobit, after the last independent variable type a comma and the letters ll and ul (e.g., tobit ratio ada pover, ll ul). This censors the model at the lower limit and upper limit (i.e., uses the lowest and highest values as the censoring points). You can select a censoring point [i.e., ll (17)]. If censoring is only one side, you may use just one censor point (e.g., tobit ratio ada pover, ll) After running a tobit model, type quadchk (if these results differ greatly from the tobit results it means that you probably shouldn’t use the tobit results). After probit or logit commands you can eliminate all the convergence output by placing “nolog” at the end of the command line: probit vote ada99, bush00, nolog
Long Command Lines: If the command you are entering is so long that it will
not fit on one line then type /// at the endpoint of the first line and continue the command on a second line (i.e., the line below).
Reconfigure Screen: (1) click on “Prefs”; (2) click on “Manage Preferences”; (3)
click on “Load Preferences”; (4) click on “Factory Settings.” If the something doesn’t appear as you expect, just run several equations, it will clear up. You may need to exit and then go back into Stata.
Place STATA Results in a Word File: Using the mouse, highlight the Stata
results you want to transfer into Word. Then use “ctrl c” (control c) to copy the Stata results. Go into Word. Use “ctrl v” (control v) to bring the Stata results into Word. You can “lineup” the Stata results by making sure the font is “currier new” 9 (i.e., font size or number 9). To change the font, highlight the Stata results you have placed in Word. With the highlight on, change the font to “currier new” 9 (i.e., 9 “point”). Now save as a normal Word file.
Command File or “Do File” – Creating the file: (1) Go into Stata; (2) load a
dataset; (3) Click on “Window” (at the top of the screen); (4) Click on “DoFile”; (4) Click on “New DoFile”; (5) Write the commands that you want to save (you can include loading the data file) – for example:
version 9
use c:\taxreceiveratiodata.dta
probit grh85 ccus86 par86 medinc85
probit grh87 ccus88 par87 medinc87
Note: you could input an Excel spreadsheet that had been saved as
as “tab delimited” text file, as opposed to the “use” and then Stata
file as above, by replacing the “use” line with:
insheet using “c:/taxreceiveratiodata.txt” (doesn’t appear to be case
sensitive)
Further Note: for commands requiring more than one line, type /// at
The end of the first line and continue the command on the line below.
(6) save by clicking on “File” under “Untitled” in the middle of the screen
To make changes in your “DoFile” or to use one, or more, commands out of the file do the following: (1) Click on “Window” (at the top of the screen); (2) Click on “DoFile”; (3) click on “New Do File; (4) Click on “File” under “Untitled” in the middle of the screen; (5) Click on “Open” and double click on the DoFile you want and the commands in the file will appear – you can either change/add commands or highlight existing commands and “copy” a command and then “paste” it in the Stata command line.
To run an entire “DoFile”: (1) Click on File in the upper left side of the screen; (2) Click on “Do” and then double click on the DoFile you want to run.
Show Last Command: “page up” key (“page down” for reverse direction)
Sampling: to randomly select 10.5% of the cases from your dataset type:
sample 10.5 You can save this smaller sample (e.g., for “Small Stata”).
Select Cases by Scores on a Variable: logit nafta avmich if divrk>25 (only
uses cases where “divrk” is greater than 25; use >=25 for 25 or greater) If selecting by a particular year you need to use two consecutive equal signs. Thus to list the scores on variable “race” for 1990 type: list race if year==1990 (two consecutive equal signs). To select on two variables at the same time use “&”: logit nafta avmich if party==1 & south==0 Missing data are a great problem with this procedure. You can use two commas if you have multiple sets of instructions after the last independent variable. For example, to specify lower and upper censoring points in tobit and use only observations where variable “state” =1:
tobit ratio ada85 par85, ll ul, if state==1
You can also select cases by scores on a variable using the “keep” command prior to statistical analysis. For example, to select cases scoring “2” on variable “brown” (with possible scores of 1, 2 and 3) you could use the following command: keep if (brown==2). To use cases with scores of 1 and 2 on brown type: keep if (brown== 1 & 2). To use cases with a score of less than 10,000 on a continuous variable “income” type:
keep if (income <10000) or for 10,000 and less type:
keep if (income <=10000). Make sure you don’t save the data because you’ll lose all the dropped observations. If you are using a “do” file to prevent permanent loss of data than have the last command reinstall the original dataset.
Select Cases by Observation: In a data set with 100 observations, to use
observations 1, 2529 and 34100 type: drop in 2/24 (press “enter”)
drop in 30/33 (press “enter”) and then run regression
Deleting Observations from a Dataset: Read the dataset into Stata. In a
dataset in which “year” was a variable and I wanted to take data from the years 1985, 1987, 1988, 1991, 1992, 1995, 1996, 2000 and 2005 from a dataset that was annual from 1880 to 2008 I did the following:
drop if year<1985
drop if year==1986
drop if year==1989
drop if year==1990
You get the picture. I don’t know how to drop consecutive years (e.g., 1989 and 1990) in one command. When you’ve deleted all the years you don’t want you will be left with those you do want. Then, using the data editor you can cut and paste the new dataset into Excel. You might “google” both “drop” and “keep” in Stata. There may be easier ways to do this than that described above.
Stacking Data – How to Change it: To change a dataset stacked by state (e.g.,
observations 120 are 20 consecutive annual observations on state #1 with observation 21 being the first observation on state #2) to a dataset stacked by year (e.g., observations 150 are the scores for 1985 on each of the 50 states – stnum = state number): sort year stnum
Transpose Rows and Columns: xpose, clear Since the xpose command
eliminates letter names for variables, it might be useful to use the xpose command on a backup file while having a primary file containing the variable names. You could then transpose the variable name column or row in Excel and cut and paste the variable names into the xpose file.
Show scores on a particular observation: to show the score on variable dlh for
the 19^{th} state (stcode is the variable name) and the year 1972 (year as the variable name) type: list dlh if stcode==19 & year==1972
Entering a Series of Independent Variables: You can enter a series of
consecutive independent variables by subtracting the last independent variable from the first. For example, suppose you have 50 state dummy variables that appear in consecutive order in your Stata dataset (e.g., ala, ak, etc. through wy). Instead of entering each independent variable by name, you could type: alawy and every variable beginning with “ala” and ending with “wy” would be entered.
String Variables to Numeric Variables: Stata cannot read variables which
appear in the Data Editor in “red” (i.e., string variables – letters or numbers that are in red). To convert a “red”/string variable, d3, to a numeric variable (also named “d3”) you need to convert the string variable to another variable (“place” in the example ahead), set this new variable equal to d3 and delete the created variable (i.e., place). The word “force” is part of the process and not a variable name. Proceed as follows:
destring d3, generate(place) force
drop d3
gen d3=place
drop place
Mathematical Procedures: addition +; subtraction ; multiplication: *; division /
Recoding a Variable: To convert a score of 1 into 2 and vice versa on variable
grhcum type: recode grhcum (1=2) (2=1) You can also use multiple procedures with nonconsecutive changes in one command. For example if you have a variable “vote” with 4 categories of responses (0, 1, 2, and 3) and want to have 0, 1 and 3 read as 0 while 2 becomes read as 1 type the following: recode vote (3=0) (1=0) (2=1) To put combine two consecutive categories use “/” thus to get 1 and 2 read as “1” type: recode cons (1/2 = 1). To recode a variable that ranged from 0 to 1 (and assumed any value in between) into just 0 and 1, I typed the following:
recode demcont (.0001/.5 = 0) (.5001/1.0 = 1) Note: the recode command does not recognize “<” and “>.” To create and recode a variable that comprises several variables (e.g., Democratic control includes both houses of the legislature plus the governorship):
gen lhdempc= lhdempro
recode lhdempc (.0000/.5 = 0) (.5001/1 = 1)
gen uhdempc= uhdempro
recode uhdempc (.0000/.5 = 0) (.5001/1 = 1)
gen demcont = lhdempc + uhdempc + demgov
recode demcont (.0001/2.999 = 0) (3 = 1)
To recode nonconsecutive numbers use multiple commands. In creating state dummy variables from a state number variable (“stnum” coded 1 through 50) I did the following: gen al=stnum then with a second command: recode al (1=1) (else=0) To recode a percentage variable, “cons,” into three categories (e.g., 033=1, etc.) type: recode cons (0/33=1) (34/66=2) (67/100=3) or you can accomplish the same operation as follows: gen cons1 = 1 if cons < 34 (press “enter”)
replace cons1 = 2 if cons >= 34 (press “enter”)
replace cons1 = 3 if cons >= 67 (press “enter”) (double check which way the arrows point – think through if it should be “<” or “>”)
Note: if you are using the above commands for one value you need two
consecutive equal signs. Thus, gen cons1=1 if cons ==34 (would be if you wanted a score of “1” on cons1 to equal a score of 34 on cons).
Recoding to Percentiles: There is a command called the “xtile” command that will recode the observations based on which percentile (ranges) of a distribution the data are in.
xtile lownetinc5 = networthlow_06, nq(5)
Where the new variable would be “lownetinc5” , the old variable would be “networthlow_06” and the number of categories for the new variable would be indicated by the nq (5) if you wanted 5 categories.
Absolute Values: to recode a variable with positive and negative values
to all positive values type: gen margin= abs(diff) This converted
negative values on “diff” to all positive for new variable “margin.”
Converting electoral “margin” into two categories (less than 3% = 1 and greater than 3% = 0), I did the following: (1) gen margin3less=.
(2) replace margin3less=1 if margin<.03001
(3) replace margin3less=0 if margin>.03
Percentage Change Variable:
tsset stnum year, yearly (means time series)
gen income = (pcdincpcdinc[_n1])/pcdinc[_n1]
gen pcdincpch=income*100
Percentage Change Over Time:
For a dataset stacked by state and year (obs. 124 were for state #1, with
obs. 25 being the first year for state #2) to get the percentage change in population (popi) over presidential administrations beginning in 1981 and ending with 2004 (i.e., change over 20012004) I did the following (after the data were “tsset”):
gen pchange = (f3.popipopi)/popi
list pchange if year == 1981 & 1985 & 1989 & 1993 & 1997 & 2001
Square Root: square root of variable pop or spop type: gen spop = sqrt(pop)
(no space between sqrt and (pop)
Logarithms: to convert variable X to a log: gen lnx = ln(x)
Descriptive Statistics – type: summarize cons party stinc (to get the median –
i.e., 50^{th} percentile – type: summarize cons party stinc, detail)
If you have missing data and want the statistics based on only those cases used in a regression do the following: (1) run the regression/logit, etc.; (2) after receiving the results type the following in the command line: estat summarize
Z Scores: to standardize cons type: egen consst = std (cons) (i.e., the new variable name is consst or: (1) download “center” command: ssc install center (2) to standardize cons type: center cons (which produces a new variable called c_cons) (3) then type: summarize cons (to obtain the standard deviation) (4) then type: gen consst=c_cons/standard deviation from step 3
Frequencies: to obtain the frequencies on one variable (e.g. ada94) type:
tabulate ada94 You can add the mean and standard deviation by:
tabulate ada94, sum(ada94) You can obtain frequencies over a limit
range of observation (e.g., 1 through 10) by:
tabulate ada94 in 1/10
Addition/Summation Over Time: given a dataset stacked by state (e.g.,, obs.
147 are 47 consecutive years for Alabama, with obs. 48 being the first year for Alaska, etc.) and variable year telling the year and stnum the number of the state, to find the mean on variable lhdem over the 19852002 period for each state type:
tabulate stnum if year>1984 & year<2003, summ (lhdem)
Note: If you want to make every observation for a particular year have the average value, 63.21, for variable statepop for that year type:
gen statepop = 63.21 if year==1985
Cross Tabulation and Measures of Association:
type: tabulate grh85 par85, row column all (“row” and
“column” yield row and column percentages, “all” yields statistics – Kendall’s tau, gamma and Cramer’s V – you can ask for either row or column percentages, or as above, both – if you want Fischer’s Exact test, add “exact” after “all”). If an error message says “too many values” you may need to recode one or both variables. For a three variable table either: tabulate tax1 cons1 if party==1, row column all
or you need to “sort” by the control variable. For example, to use the two variables above controlling for party type: sort par85 (press “enter”)
by par85: tabulate grh85 grh87, row column all exact (press “enter”)
Correlation: correlate tax cons (to correlate tax and cons – can add more
variables)
Partial Correlation: pcorr tax cons party stinc
Kendall’s tau: ktau tax cons (can add more variables)
Spearman rank correlation: spearman tax cons (can add more variables)
Gamma: see “cross tabulation and measures of association” above or tabulate
tax cons, gamma or tab tax cons, gam
Note: you can only use two variables at a time and you may need to recode before obtaining a gamma statistic – you can have 5 categories per variable but I don’t know how many more categories are allowed
if you use the procedure listed at the beginning of “Cross Tabulation and Measures of Association” you can avoid recodes.
Cronbach’s Alpha: Cronbach’s Alpha examines reliability by determining the
internal consistency of a test or the average correlation of items (variables) within the test. In Stata, the alpha command conducts the reliability test. For example, suppose you wish to test the internal reliability of ten variables, v1 through v10. You could run the following:
alpha v1v10, item In this example, the item option displays the effects of removing an item from the scale. If you want to see if a group of items can reasonably be thought to form an index/scale you could also use Cronbach’s alpha. For example: alpha a3e a3g a3j a3o, c i The “alpha” score in the “Test scale” row (“alpha” is in the far right column and “Test scale” is a row) should be about .80 (maximum is 1.0) to show a high degree of reliability of the components. However, William Jacoby said the .80 threshold is very high. He would’ve gone lower to .70 (but would never use a scale with a reliability below .5 because you’d have more error variance than substantive variance). If the variables are measured on different scales you may want to standardize them. If so then add “s” to the above command (i.e., alpha a3e a3g a3j a3o, c i s). Since the score for a variable in the “Test scale” column is what the “Test scale” number would be if that variable were deleted, you can maximize the score in the “Test scale” row by deleting any variables whose score in the “alpha” column is greater than the alpha in the “Test scale” row. You can make the scale into a variable by typing: alpha a3e a3g a3j a3o, c gen(anscale) Note: “anscale” is arbitrary (you can pick any name you want – this will now appear as a variable). If you want to exclude those respondents that had a particular score on a variable (e.g., using scores 1 and 2 on variable “petition” but excluding 3) then do the following: alpha a3e a3g a3j a3o if partition==1&2, c i s) For a better understanding see “Intermediate Social Statistics: Lecture 6. Scale Construction” by Thomas A.B. Snijders – saved as adobe file: StataMokkenCronbach.
Factor Analysis: You could factor analyze a group of variables (principle
components method by typing: factor a3e a3g a3j a3o, pcf
Look for eigenvalues greater than 1.0 (signifying that the variables in the factor explain more of the variance than individual variables). The entries in the “factor” column are the correlations of that particular variable with the underlying factor. The number in the “cumulative” column tells how much of the variance in the variables you have factor analyzed are explained by all of the factors at the point (i.e., the first entry tells how much of the variance is explained by factor 1 while the second entry tells how much of the variance is explained by factors 1 & 2 together). The score in the “uniqueness” column tells how much of the explained variance is unique to that variable. For example, a score of .61 would indicate that 61% of the variance explained by that particular variable is not explained by the other variables. If you then type “rotate” (default approach – varimax with orthogonal factors – i.e., the factors are not correlated with each other) it will maximize the fit of the dominant variables on that factor. This setting is recommended when you want to identify variables to create indexes or new variables without intercorrelated components. To create new variables (after running “factor” and “rotate”) type: predict factor1 factor2 (you can use whatever names you want to the right of “predict”). They will now appear as variables.
polychoric a3a a3o (need to add this command by typing findit polychoric) Note: tetrachoric for dichotomous variables
Mokken Scaling: “Mokken scaling is an iterative scalebuilding technique, and
as it is nonparametric is especially suitable for skewed and binary items. It is based on Guttman scales, which are unidimensional, ordinal scales of binary items along a continuum. A positive answer to one item of a certain ‘difficulty’ indicates that all other items of lesser difficulty have also been
answered positively. For example, a positive response to one particular (rare) item indicates that other (more common) items have also been endorsed. Mokken scaling can also use polytomous items, and is a probabilistic version of Guttman scaling. Loevinger’s Hcoefficient is used for interpretation. By convention, 0.3 ≥ H < 0.4, 0.4 ≥ H < 0.5 and H ≥ 0.5 indicate weak, moderate and strong scales respectively. Higher
H values indicate higher item discrimination power, and thus more confidence in ordering of respondents. The Hvalue equals [1 – (observed Guttman errors/predicted Guttman errors)]. Expected Guttman errors are the probability that the items are chosen by chance, while observed Guttman errors are the number of times items are endorsed as if not in an
ordered sequence. Therefore, a coefficient of ≤ .4 demonstrates a scale with items with a 60% rate of Guttman errors. Following a recommended procedure, which involves increasing the coefficient value until the most interpretable solution is found, items that demonstrate poor discriminability are excluded from the scale. Results can be compared to factor
analysis. In general, factor loadings larger than .5 result in Hcoefficients greater than .3. Reported scales are ordered in terms of difficulty, ie. the most infrequently endorsed items feature at the top.” (Frank Doyle, et. al., “Exhaustion, Depression and Hopelessness in Cardiac Patients: A Unidimensional Hierarchy of Symptoms Revealed by Mokken Scaling,” Royal College of Surgeons in Ireland, 2011, pp. 2930). “Loevinger coefficients Mokken (1971) proposed to measure the quality of the pair of items i; j by the Loevinger coefficient Hij = 1 Observed Nij (1; 0)
Expected Nij (1; 0): The ‘expected’ value is calculated under the null model that the items are independent. If no errors are observed, Hij = 1;
if as many errors are observed as expected under independence, then
Hij = 0. For example with two items with means _Xi: = 0:2; _Xj: = 0:6,
for a sample size of n = 100 the expected table is
Xjh = 0 Xjh = 1
Xih = 0 32 48 80
Xih = 1 8 12 20
40 60
There are 8 errors in the above table. Now suppose the errors were reduced to just 2 (i.e., 2 in the cell which contains 8). Then Hij = 1 – (2/8) = 0:75. Thus, a good scale should have Loevinger H coefficients that are large enough for all pairs i; j with i < j. Rules of thumb that have been found useful are as follows: Hij < 0:3 indicates poor/no scalability;
0:3 < Hij < 0:4 indicates useful but weak scalability;
0:4 < Hij < 0:5 indicates medium scalability;
0:5 < Hij indicates good scalability.
Similarly, Loevinger’s coefficients can be defined for all pairwise errors for a given item (Hi ) and for all pairwise errors for the entire scale (H).
Although you can run the procedure without specifying a value for Loevinger’s H, you can set levels as in the following command (“c” is the value set). msp a3f a3h a3i a3k, c(.4)
Below are some additional commands that can be used:
msp a3aa3o, c(.4)
msp a3aa3o, pairwise c(.4)
loevh a3aa3o, pairwise
Mokken scaling can be used in a confirmatory way, with a given set of
items (where the order can be determined empirically) as well as in an exploratory way. In the exploratory method, a set of items is given,
and it is tried to find a wellscalable subset. This is done by first finding the pair with the highest Hij as the starting point for the scale; and by then consecutively adding items that have the highest values of the Loevinger coefficients with the items already included in the scale. This procedure can then be repeated with the remaining items to find a further scale among those. The reliability can be estimated also from the interitem correlations. The Mokken scaling module is not part of the normal Stata program and must be downloaded. In the command line type: findit msp
Multidimensional Scaling: Assume we have information about the American
electorate’s perceptions of thirteen prominent political figures from the period of the 2004 presidential election. Specifically, we have the perceived dissimilarities between all pairs of political figures. With 13 figures, there will be 78 distinct pairs of figures. Rankorder pairs of political figures, according to their dissimilarity (from least to most dissimilar). Multidimensional Scaling (MDS) tries to find a set of k points in mdimensional space such that the distances between pairs of points
approximate the dissimilarities between pairs of objects. (adapted from William Jacoby and David Armstrong, “Multidimensional Scaling 1”, used at the Measurement, Scaling and Dimensional Analysis short course at the 2011 ICPSR Summer Program – available from William Jacoby’s website). The following command generates the mds default estimation:
mds a3aa3o, id(partic)
Note: you need to specify an “id” – the name of the variable that gives the observation number. In the command line above, the variable “partic” gives the number assigned to each participant in the study.
View Scores on a Variable: list (then click on variable names and press “enter”)
Graphs/Plots: run a regression prior to each step below.
to graph residuals by predicted values: rvfplot
graph residuals by an ind. variable cons: rvpplot cons
plot cons by tax type: plot cons tax
leverage vs. residual sq. plot: lvr2plot
added variable plots (useful for uncovering observations exerting disproportionate influence): avplots
box plots: graph box cons party tax (shows median, 25^{th}, 75^{th} percentile)
histogram of cons: graph twoway histogram cons
scatter plot of tax (on y axis) and cons type: scatter tax cons
>>> to get a graph of variables restax and rescon with both dots and
a regression line type:
graph twoway lfit restax rescons  scatter restax rescons
Interaction Term: gen nsnt=nsa*nt1 (+ – / for other mathematical procedures)
Dummy Variables: Automatic Creation: if you have a variable entitled “year”
and want to create dummy year variables type: xi i.year To delete this variable type: drop _I*
Interaction Variables: Automatic Creation: to create an dummy variable for
year and gender type: xi i.year*i.gender To drop type: drop _I*
Residuals and Predicted Values
1. run main equation: fit tax cons party stinc
(I believe you can replace “fit” with regres, logit, probit, etc. – “fit” is just for regression – I don’t think “fit” works with logit, etc.)
2. predict yhat
3. gen res=taxyhat
4. list tax yhat res
Stepwise: allows you to specify significance levels and reestimate the model
deleting variables that are less significant than the selected threshold. For example: stepswise, pr(.2) hierarchical: regress tax cons party stinc
would mean Stata would estimate the model with all three independent variables and then reestimate excluding any independent variable that was not significant at the .20 level. Can use with probit, logit, etc.
Regression Diagnostics: Run a regression with regress. Now in the command
line type: dfbeta (you’ll see each DF and the name of each independent variable – type “list” and then the name of the independent variable you are interested in). For other diagnostics run a regression. For standardized residuals type: predict esta if e(sample), rstandard (in the command line). You will see “esta” appear in the variable list. Now type: list esta and you will see the values. For studentized residuals do try the following after a regression: Predict estu if e(sample), rstudent (estu will now appear as a variable). For Cooks distance type: predict cooksd if e(sample), cooksd after running a regression.
Multicollinearity: after running a regression using regress, type: vif (or: estat vif)
in the command line. Subtract the number in the 1/VIF column from 1
to obtain the percentage of variation in that independent variable which is explained by all other independent variables. In the VIF column, numbers above 30 indicate high variance inflation (i.e., high multicollinearity).
Doesn’t work in probit/logit. Since at this point you’re only interested in multicollinearity, reestimate a probit/logit equation in regression and then follow the procedure above.
Autocorrelation: regdw (replaces regress command and executes Durbin
Watson test). The data need to be dated – for example, if your data are annual and you have a variable called year, then before you do a regression type: tsset year and press “enter” (or after running regression with “regress” type dwstat). The command corc (replaces regress command and executes CochraneOrcutt correction for first
order autocorrelation – note data must be dated, see regdw discussion above). You can save the first observation by using the PraisWinsten (replace “regress” with “prais”).
Heteroscedasticity: run regression replacing regress with fit and then, as a next
command, type: hettest and press enter. If you have significant heteroscedasticity, use the “robust’ estimation option. Thus, for a “robust” regression type: rreg tax cons party stinc
Lagged Independent Variable: to lag variable ussr by one time period type:
You can lag a variable one time period by typing “l.” in front of the variable. Thus, l.ussr should be a one period lag of ussr. You can also do this by typing: gen xussr = ussr[_n1] which will create a new lagged variable: xussr. Remember that your data must be dated (see regdw discussion under Autocorrelation above). Lagging will cost one data point, when you run the regression it running it on your sample minus the first observation. There is an “underline” before the “n1.”
First Differences: To create a variable that tells the difference in scores from
one time period to the next (e.g., 20032002), type “d.” in front of the variable. Thus, to difference ussr type d.ussr
Moving Average Variable: To transform state ideology from an annual variable
(stideoan) to a moving average where years 14 were the same score (because our the data series we needed extend four years prior to the beginning of the time period for which data were collected) and years 5 and beyond were the average of the current year plus the immediately preceeding 3 years (each year equally weighted) type:
xtset stnum year (note: stnum = state number and year=year)
tssmooth ma stdeoan_ma=stideoan , window(3 1 0)
To generate a 12 year moving average of Democratic control (assuming you have already generated the Democratic control variable – e.g., 1= Democratic governor + Democratic majority of both houses of the state legislature in year “t” – how to do this is explained later in this file)
type:
tsset stnum year, yearly
gen demcont12 = (demcont[_n12] + demcont[_n11] + demcont[_n10] + demcont[_n 9] + demcont[_n8] + demcont[_n7] + demcont[_n6] + demcont[_n5] + demcont[_n 4] + demcont[_n3] + demcont[_n2] + demcont[_n1])/12
Equality of Regression Coefficients: use the suest (seemingly unrelated
regression) postestimation command. Estimate model 1, then model 2, and it forms the seemingly unrelated variancecovariance matrix (estimates) for the combined set of coefficients. With that, you can test if some coefficient from model 1 is equal to some coefficient from model 2.
Standardized Coefficients: in regression just add ,beta to the end of the
command line – thus: regress tax cons party stinc, beta
To obtain standardized coefficients for probit, logit and multinomial logit
first estimate the desired equation. After the results appear type the following in the command line: listcoef (You may need to download this option from Stata – it will work but may not be built into the package – to download you need to be connected to the internet and type the following in the command line: ssc install listcoef – if that doesn’t work try findit listcoef – then you need click on the appropriate link). If you are interested in the relative value of coefficients, use the coefficients in the “bStdXY” (i.e., the coefficients in this column should be identical to what you receive with the “beta” command in regression). Additionally, two bStdXY coefficients have virtually the same ratio as do the same two bStdX coefficients).
Marginal Effects: run regress, probit or logit. Then in command line type: mfx
In probit you can also get the marginal effects of each independent variable by replacing probit with dprobit
Comparing Models in Probit/Logit (i.e., nesting – like F test in regression
for the equality of two R squareds) – from page 144 of J. Scott Long and Jeremy Freese, Regression Models for Categorical Dependent Variables Using Stata, 2^{nd}. ed. –
probit involvem repcont demcont ablegal fund1 catholic
estimates store fullmodel
probit involvem ablegal fund1 catholic
estimates store smallmodel
lrtest fullmodel smallmodel
“Weights”/Downloading Data – If you are downloading data and Stata refuses
to accept the file by saying “weights not allowed” or something like that put quotations around the file name. Thus, if the file name is test, then in the command line type: use “test” (press enter) Put the parentheses around everything expect the word: use (thus use “C:/test” not “use C:/test”)
Word Responses into Numerical Responses: If you the responses are words
(e.g., strong agree, etc.) and you want to convert them to numerical values, one suggestion is to cut and paste the dataset into Excel and use the “Find and Replace” option – you can ask Excel to “find” words and then “ replace” with numbers. You can see if there is a numerical code that the words translate into (e.g., strong agree becomes “1,” etc.) by the following procedure: (1) click on “Data” at the top of the screen; (2) click on “Data Editor”; (3) I think you can choose either “Edit” or “Browse”; (4) click on “Tools”; (5) click on “value labels”; (6) click on “Hide all value labels” – numbers should appear at this point. There is a way to permanently convert words into numbers. Go to data editor (choose “edit”, not “browse”) and select (i.e., highlight) the variable (one variable at a time) you are interested in (e.g. q1). Right click the mouse and choose “Value Labels” then choose “ Assign Value Label to Variable 'q1’” and finally, choose “None.” This will erase the labels for the variable and leave the numeric values.
Apakah itu analisis faktor
http://en.wikipedia.org/wiki/Factor_analysis
Beda CFA dan EFA?
http://www.indiana.edu/~statmath/stat/all/cfa/cfa3.html
Stata tentang faktor analisis
http://www.ats.ucla.edu/stat/stata/output/fa_output.htm
http://www.salaswright.com/wpcontent/uploads/2012/05/CFAusingStata.pdf
http://www.salaswright.com/wpcontent/uploads/2012/05/SalasWrightSEMNotes7.18.12.pdf
17 October 2012
This article is writen by Chuck Huber, Senior Statistician
you can see all the article through this link http://blog.stata.com/?s=SEM
Originally published by Aaron Beck and colleagues in 1961, the BDI marked an important change in the conceptualization of depression from a psychoanalytic perspective to a cognitive/behavioral perspective. It was also a landmark in the measurement of depression shifting from lengthy, expensive interviews with a psychiatrist to a brief, inexpensive questionnaire that could be scored and quantified. The original inventory consisted of 21 questions each allowing ordinal responses of increasing symptom severity from 03. The sum of the responses could then be used to classify a respondent’s depressive symptoms as none, mild, moderate or severe. Many studies have demonstrated that the BDI has good psychometric properties such as high testretest reliability and the scores correlate well with the assessments of psychiatrists and psychologists. The 21 questions can also be grouped into two subscales. The affective scale includes questions like “I feel sad” and “I feel like a failure” that quantify emotional symptoms of depression. The somatic or physical scale includes questions like “I have lost my appetite” and “I have trouble sleeping” that quantify physical symptoms of depression. Since its original publication, the BDI has undergone two revisions in response to the American Psychiatric Association’s (APA) Diagnostic and Statistical Manuals (DSM) and the BDIII remains very popular.
The Stata Depression Inventory
Since the BDI is a copyrighted psychometric instrument, I created a fictitious instrument called the “Stata Depression Inventory”. It consists of 20 questions each beginning with the phrase “My statistical software makes me…”. The individual questions are listed in the variable labels below.
. describe qu1qu20 variable storage display value name type format label variable label  qu1 byte %16.0g response ...feel sad qu2 byte %16.0g response ...feel pessimistic about the future qu3 byte %16.0g response ...feel like a failure qu4 byte %16.0g response ...feel dissatisfied qu5 byte %16.0g response ...feel guilty or unworthy qu6 byte %16.0g response ...feel that I am being punished qu7 byte %16.0g response ...feel disappointed in myself qu8 byte %16.0g response ...feel am very critical of myself qu9 byte %16.0g response ...feel like harming myself qu10 byte %16.0g response ...feel like crying more than usual qu11 byte %16.0g response ...become annoyed or irritated easily qu12 byte %16.0g response ...have lost interest in other people qu13 byte %16.0g qu13_t1 ...have trouble making decisions qu14 byte %16.0g qu14_t1 ...feel unattractive qu15 byte %16.0g qu15_t1 ...feel like not working qu16 byte %16.0g qu16_t1 ...have trouble sleeping qu17 byte %16.0g qu17_t1 ...feel tired or fatigued qu18 byte %16.0g qu18_t1 ...makes my appetite lower than usual qu19 byte %16.0g qu19_t1 ...concerned about my health qu20 byte %16.0g qu20_t1 ...experience decreased libido
The responses consist of a 5point Likert scale ranging from 1 (Strongly Disagree) to 5 (Strongly Agree). Questions 110 form the affective scale of the inventory and questions 1120 form the physical scale. Data were simulated for 1000 imaginary people and included demographic variables such as age, sex and race. The responses can be summarized succinctly in a matrix of bar graphs:
Classical statistical analysis
The beginning of a classical statistical analysis of these data might consist of summing the responses for questions 110 and referring to them as the “Affective Depression Score” and summing questions 1120 and referring to them as the “Physical Depression Score”.
egen Affective = rowtotal(qu1qu10) label var Affective "Affective Depression Score" egen physical = rowtotal(qu11qu20) label var physical "Physical Depression Score"
We could be more sophisticated and use principal components to create the affective and physical depression score:
pca qu1qu20, components(2) predict Affective Physical label var Affective "Affective Depression Score" label var Physical "Physical Depression Score"
We could then ask questions such as “Are there differences in affective and physical depression scores by sex?” and test these hypotheses using multivariate statistics such as Hotelling’s Tsquared statistic. The problem with this analysis strategy is that it treats the depression scores as though they were measured without error and can lead to inaccurate pvalues for our test statistics.
Structural equation modeling
Structural equation modeling (SEM) is an ideal way to analyze data where the outcome of interest is a scale or scales derived from a set of measured variables. The affective and physical scores are treated as latent variables in the model resulting in accurate pvalues and, best of all….these models are very easy to fit using Stata! We begin by selecting the SEM builder from the Statistics menu:
In the SEM builder, we can select the “Add Measurement Component” icon:
which will open the following dialog box:
In the box labeled “Latent Variable Name” we can type “Affective” (red arrow below) and we can select the variables qu1qu10 in the “Measured variables” box (blue arrow below).
When we click “OK”, the affective measurement component appears in the builder:
We can repeat this process to create a measurement component for our physical depression scale (images not shown). We can also allow for covariance/correlation between our affective and physical depression scales using the “Add Covariance” icon on the toolbar (red arrow below).
I’ll omit the intermediate steps to build the full model shown below but it’s easy to use the “Add Observed Variable” and “Add Path” icons to create the full model:
Now we’re ready to estimate the parameters for our model. To do this, we click the “Estimate” icon on the toolbar (duh!):
And the flowing dialog box appears:
Let’s ignore the estimation options for now and use the default settings. Click “OK” and the parameter estimates will appear in the diagram:
Some of the parameter estimates are difficult to read in this form but it is easy to rearrange the placement and formatting of the estimates to make them easier to read.
If we look at Stata’s output window and scroll up, you’ll notice that the SEM Builder automatically generated the command for our model:
sem (Affective > qu1) (Affective > qu2) (Affective > qu3) (Affective > qu4) (Affective > qu5) (Affective > qu6) (Affective > qu7) (Affective > qu8) (Affective > qu9) (Affective > qu10) (Physical > qu11) (Physical > qu12) (Physical > qu13) (Physical > qu14) (Physical > qu15) (Physical > qu16) (Physical > qu17) (Physical > qu18) (Physical > qu19) (Physical > qu20) (sex > Affective) (sex > Physical), latent(Affective Physical) cov(e.Physical*e.Affective)
We can gather terms and abbreviate some things to make the command much easier to read:
sem (Affective > qu1qu10) /// (Physical > qu11qu20) /// (sex > Affective Physical) /// , latent(Affective Physical ) /// cov( e.Physical*e.Affective)
We could then calculate a Wald statistic to test the null hypothesis that there is no association between sex and our affective and physical depression scales.
test sex ( 1) [Affective]sex = 0 ( 2) [Physical]sex = 0 chi2( 2) = 2.51 Prob > chi2 = 0.2854
Final thoughts
This is an admittedly oversimplified example – we haven’t considered the fit of the model or considered any alternative models. We have only included one dichotomous independent variable. We might prefer to use a likelihood ratio test or a score test. Those are all very important issues and should not be ignored in a proper data analysis. But my goal was to demonstrate how easy it is to use Stata’s SEM builder to model data such as those arising from the Beck Depression Inventory. Incidentally, if these data were collected using a complex survey design, it would not be difficult to incorporate the sampling structure and sample weights into the analysis. Missing data can be handled easily as well using Full Information Maximum Likelihood (FIML) but those are topics for another day.
If you would like view the slides from my talk, download the data used in this example or view a video demonstration of Stata’s SEM builder using these data, please use the links below. For the dataset, you can also type use followed by the URL for the data to load it directly into Stata.
Slides:
http://stata.com/meeting/sandiego12/materials/sd12_huber.pdf
Data:
http://stata.com/meeting/sandiego12/materials/Huber_2012SanDiego.dta
YouTube video demonstration:
http://www.youtube.com/watch?v=Xj0gBlqwYHI
References
Beck AT, Ward CH, Mendelson M, Mock J, Erbaugh J (June 1961). An inventory for measuring depression. Arch. Gen. Psychiatry 4 (6): 561–71.
Beck AT, Ward C, Mendelson M (1961). Beck Depression Inventory (BDI). Arch Gen Psychiatry 4 (6): 561–571
Beck AT, Steer RA, Ball R, Ranieri W (December 1996). Comparison of Beck Depression Inventories IA and II in psychiatric outpatients. Journal of Personality Assessment 67 (3): 588–97
Bollen, KA. (1989). Structural Equations With Latent Variables. New York, NY: John Wiley and Sons
Kline, RB (2011). Principles and Practice of Structural Equation Modeling. New York, NY: Guilford Press
Raykov, T & Marcoulides, GA (2006). A First Course in Structural Equation Modeling. Mahwah, NJ: Lawrence Erlbaum
Schumacker, RE & Lomax, RG (2012) A Beginner’s Guide to Structural Equation Modeling, 3rd Ed. New York, NY: Routledge
new SEM features in STATA
http://www.stata.com/stata12/structuralequationmodeling/
apa itu SEM?
http://www.stata.com/stata12/structuralequationmodeling/explanation/
http://www.stata.com/capabilities/structuralequationmodeling/
Video STATA untuk pengolahan SEM
[youtube]http://www.youtube.com/watch?v=Xj0gBlqwYHI&feature=plcp[/youtube]
Paper about SEM STATA
http://www.stata.com/meeting/chicago11/materials/chi11_drukker_sem.pdf
http://www.surveydesign.com.au/tips.html
Pertanyaan sederhana, analisis statistik mana yang digunakan karena begitu banyaknya pilihanpilihan alat analisis dan penggunaannya yang spesifik?
http://www.ats.ucla.edu/stat/stata/whatstat/whatstat.htm
http://www.ats.ucla.edu/stat/mult_pkg/whatstat/
Namun, untuk lebih memperjelas pilihan statistik diatas, sebaiknya kita mereview perbedaan jenis data
http://www.ats.ucla.edu/stat/mult_pkg/whatstat/nominal_ordinal_interval.htm
update stata syntax – can download all of these programs to your computer from the Stata command window by typing.
do http://www.ats.ucla.edu/stat/stata/ado/copyats "Spesial" Logit regression http://www.ats.ucla.edu/stat/stata/webbooks/logistic/chapter3/statalog3.htm http://www.uk.sagepub.com/burns/website%20material/Chapter%2024%20%20Logistic%20regression.pdf

Articles
 May 2015
 November 2014
 October 2014
 September 2014
 August 2014
 June 2014
 May 2014
 April 2014
 March 2014
 February 2014
 January 2014
 December 2013
 November 2013
 October 2013
 September 2013
 August 2013
 July 2013
 June 2013
 April 2013
 March 2013
 December 2012
 November 2012
 October 2012
 September 2012
 August 2012
 July 2012
 June 2012
 May 2012
 April 2012
 March 2012
 February 2012
 January 2012

Calendar
June 2020 M T W T F S S « May 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 
Meta

Add Widgets (Secondary Sidebar)
This is your Secondary Sidebar. Edit this content that appears here in the widgets panel by adding or removing widgets in the Secondary Sidebar area.