// Table 4.6 use "https://statisticalhorizons.com/wp-content/uploads/college.dta", clear eststo clear eststo: sem (gradrat act <- csat lenroll private stufac rmbrd), cov(e.gradrat*e.act) method(mlmv) #delimit ; esttab using test.tex, cells("b(fmt(3) label(Coefficient)) se(fmt(3) label(Standard Error)) t(fmt(2) label(t Statistic)) p(fmt(4) label(p Value))") order(_cons) coeflabel(_cons "Intercept") nomtitle nonumber title(Regression that predicts GRADRAT Using Direct ML) keep(gradrat:) eqlabels("", none) // Removes equation label booktabs replace; #delimit cr
Showing posts with label booktabs. Show all posts
Showing posts with label booktabs. Show all posts
Jan 11, 2018
Analysis of incomplete data with full information ML using Stata
The code below allows replicating the example of Allison (2002, pp. 25-27).
Labels:
booktabs,
esttab,
Missing values,
sem,
Textbooks
Jan 10, 2018
Expectation Maximization (EM) for missing values using Stata
The code below allows replicating the analyses from Allison (2002, pp. 21-3).
use "https://statisticalhorizons.com/wp-content/uploads/college.dta", clear // Table 4.1 eststo clear estpost summarize gradrat csat lenroll private stufac rmbrd act esttab using test.tex, cells("count(label(Nonmissing cases)) mean(label(Mean) fmt(2)) sd(label(SD) fmt(2))") /// nomtitle nonumber /// title(Descriptive Statistics for College Data Based on Available Cases) /// booktabs replace // Tabe 4.2
eststo clear
eststo: regress gradrat csat lenroll private stufac rmbrd
#delimit ;
esttab using test.tex, cells("b(fmt(3) label(Coefficient))
se(fmt(3) label(Standard Error))
t(fmt(2) label(t Statistic))
p(fmt(4) label(p Value))")
order(_cons) coeflabel(_cons "Intercept")
nomtitle nonumber
title(Regression that predicts GRADRAT Using Listwise Deletion)
booktabs append ;
#delimit cr
// EM imputation
mi set mlong
mi register imputed gradrat csat lenroll private stufac rmbrd act
mi impute mvn gradrat csat lenroll private stufac rmbrd act, emonly
matrix m = r(Beta_em)' // Transpose matrix of imputed means
matrix C = corr(r(Sigma_em)) // Matrix of correlations
matrix variances = diag((vecdiag(r(Sigma_em)))) // Matrix of variances
matrix sds = vecdiag(cholesky(variances))' // Vector of standard deviations
matrix descriptives = m, sds // Matrix needed for Table 4.3
// Table 4.3
esttab matrix(descriptives, fmt(2 2)) using test.tex, ///
nomtitle title("Means and Standard Deviations from the EM Algorithm") ///
booktabs append
// Table 4.4
esttab matrix(C, fmt(3 3)) using test.tex, ///
nomtitle title("Correlations from the EM Algorithm") ///
booktabs append
// Table 4.5
drop * // Get rid of data but not matrices
ssd init gradrat csat lenroll private stufac rmbrd act
ssd set observations 1302
ssd set means (stata) m
ssd set sd (stata) sds
ssd set corr (stata) C
eststo clear
eststo: sem (gradrat <- csat lenroll private stufac rmbrd)
#delimit ;
esttab using test.tex, cells("b(fmt(3) label(Coefficient))
se(fmt(3) label(Standard Error))
t(fmt(2) label(t Statistic))
p(fmt(4) label(p Value))")
order(_cons) coeflabel(_cons "Intercept")
nomtitle nonumber title(Regression that predicts GRADRAT Based on the EM Algorithm)
keep(gradrat:) eqlabels("", none) // Removes equation label
booktabs append
;
#delimit cr
Reference
Allison, Paul D. 2002. Missing Data. Sage. doi: 10.4135/9781412985079
Labels:
booktabs,
Correlation tables,
esttab,
matrix,
mi set,
Missing values,
ssd,
Textbooks
Jan 9, 2018
Dummy variable adjustment for missing values in Stata
This piece of code replicates Table 3.1 in Allison (2002).
clear
set seed 1
// Generate data
set obs 10000
drawnorm x z, ///
corr(1, .5, 1) cstorage(lower)
generate e = rnormal()
generate y = x + z + e
// Drop 1/2 of values from z
generate d = (runiform() > . 5)
generate zstar1 = z if d
replace zstar1 = . if !d
// Substitute missing values
qui sum zstar1
generate zstar2 = zstar1
replace zstar2 = r(mean) if !d
eststo clear
eststo: regress y x z
eststo: regress y x zstar1
eststo: regress y x zstar2 d
esttab using test.tex, b(2) not nostar nocons rename(zstar1 z zstar2 z) ///
mtitles("Full data" "Listwise deletion" "Dummy variable adjustment") ///
title(Regression in Simulated Data for Three Methods) replace booktabs
Reference
Allison, Paul D. 2002. Missing Data. Sage. doi: 10.4135/9781412985079
Labels:
booktabs,
esttab,
Missing values,
Simulation,
Textbooks
Subscribe to:
Posts (Atom)






