* Chapter 4: Descriptive Statistics using Stata .

* Import data .
insheet using "C:\temp\classroom.csv", comma clear

**************************.
* Descriptive Summary #1 .
**************************.

* Level 1 Descriptive Statistics .
summarize sex minority mathkind mathgain ses

* Level 2 Descriptive Statistics (start with full data file) .
collapse (mean) yearstea, by(classid)
summarize yearstea

* Level 3 Descriptive Statistics (start with full data file) .
insheet using "C:\temp\classroom.csv", comma clear
collapse (mean) housepov, by(schoolid)
summarize housepov

**************************.
* Descriptive Summary #2 .
**************************.

insheet using "C:\temp\classroom.csv", comma clear

keep if mathknow != .

* Level 1 Descriptive Statistics .
summarize sex minority mathkind mathgain ses

* Level 2 Descriptive Statistics .
collapse (mean) yearstea mathknow mathprep, by(classid)
summarize yearstea mathknow mathprep

* Level 3 Descriptive Statistics .
insheet using "C:\temp\classroom.csv", comma clear
keep if mathknow != .
collapse (mean) housepov, by(schoolid)
summarize housepov

***********************************.
* Generate Boxplots for Figure 4.2.
***********************************.

insheet using "C:\temp\classroom.csv", comma clear
graph box mathgain if schoolid <= 2, medtype(line) over(classid) by(schoolid)
graph box mathgain if (schoolid >= 3 & schoolid <= 4), medtype(line) over(classid) by(schoolid)
graph box mathgain if (schoolid >= 5 & schoolid <= 6), medtype(line) over(classid) by(schoolid)
graph box mathgain if (schoolid >= 7 & schoolid <= 8), medtype(line) over(classid) by(schoolid)

 


