// Regression Models for Categorical Dependent Variables - 2nd Edition // Chapter 2 - Stata tutorial // Long and Freese - 27Jul2005 version 9 set scheme sj set more off capture log close log using st9ch2tutorial, replace text clear use binlfp2 tabulate hc wc if age>40, row summarize age inc k5 summarize summarize k* use binlfp2, clear describe summarize age, detail tabulate hc tabulate hc, nolabel tabulate hc wc tab1 hc wc dotplot age graph export 02dotplot.emf, replace codebook age generate age2 = age summarize age2 age gen age3 = age if age>40 summarize age3 age gen agesq = age^2 gen lnage = ln(age) gen age4 = age replace age4 = 40 if age<40 summarize age4 age use recodedata2, clear recode origvar (1=2) (3=4), generate(myvar1) recode origvar (2=1) (*=0), generate(myvar2) recode origvar (2=1) (nonmissing=0), generate(myvar3) recode origvar (1/4=2), generate(myvar4) recode origvar (1 3 4 5=7), generate(myvar5) recode origvar (min/5=min), generate(myvar6) recode origvar (missing=9), generate(myvar7) recode origvar (-999=.), generate(myvar8) use gsskidvalue2, clear tabulate degree, generate(edlevel) summarize edlevel* tabulate degree edlevel1, missing gen hsdeg = (degree==1 | degree==2) if degree<. gen coldeg = (degree==3) if degree<. gen graddeg = (degree==4) if degree<. tabulate degree coldeg, missing use ordwarm2, clear gen ed12plus = (ed>=12) if ed<. gen edlt13 = (ed<=12) if ed<. gen ed1316 = (ed>=13 & ed<=16) if ed<. gen ed17plus = (ed>17) if ed<. gen wrmagree = warm recode wrmagree 1=0 2=0 3=1 4=1 tabulate wrmagree warm use gsskidvalue2, clear gen agesq = age*age gen lnincome = ln(income) summarize age agesq income lnincome gen feminc = female * income label variable agesq "Age squared" describe agesq label variable agesq describe agesq label define yesno 1 yes 0 no label define posneg4 1 veryN 2 negative 3 positive 4 veryP label define agree4 1 StrongA 2 Agree 3 Disagree 4 StrongD label define agree5 1 StrongA 2 Agree 3 Neutral 4 Disagree 5 StrongD label values female yesno label values black yesno label values anykids yesno describe female black anykids tabulate anykids label define degree 0 "no_hs" 1 "hs" 2 "jun_col" 3 "bachelor" 4 "graduate" label values degree degree tabulate degree use lfpgraph2, clear list income kid0p1 kid1p1 graph twoway scatter kid0p1 kid1p1 kid2p1 income, ytitle(Probability) graph export 02graphsimple.emf, replace graph twoway (connected kid0p1 income) (scatter kid1p1 kid2p1 income), /// ytitle(Probability) graph export 02graphsimplec.emf, replace graph twoway (connected kid0p1 kid1p1 kid2p1 income), ytitle("Probability") /// title("Predicted Probability of Female LFP") /// subtitle("(as predicted by logit model)") /// xtitle("Family income, excluding wife's") /// caption("Data from 1976 PSID-T Mroz") graph export 02graphsimpled.emf, replace graph twoway (connected kid0p1 kid1p1 kid2p1 income), /// ytitle("Probability") /// title("Predicted Probability of Female LFP") /// subtitle("(as predicted by logit model)") /// xtitle("Family income, excluding wife's") /// caption("Data from 1976 PSID-T Mroz") /// xlabel(10 20 30 40 50 60 70 80 90) graph export 02graphsimpleh.emf, replace // loading the data use science2, clear // examining the dataset describe // examining individual variables summarize work tabulate work, missing codebook work // graphing variables dotplot work // saving graphs graph export 02dotplot2.emf, replace // creating a dummy variable generate isfac = (work==1) if work<. // checking transformations tabulate isfac work, missing // labeling variables and values label variable isfac "1=Faculty in University" label define isfac 0 "NotFac" 1 "Faculty" label values isfac isfac tabulate isfac // creating an ordinal variable tabulate job, missing generate jobprst = job recode jobprst .=. 1/1.99=1 2/2.99=2 3/3.99=3 4/5=4 label variable jobprst "Rankings of University Job" label define prstlbl 1 "Adeq" 2 "Good" 3 "Strong" 4 "Dist" label values jobprst prstlbl tabulate jobprst, missing // combining variables generate pubsum = pub3 + pub6 + pub9 label variable pubsum "Total Pubs in 9 Yrs post-Ph.D." summarize pub3 pub6 pub9 pubsum graph matrix pub3 pub6 pub9 pubsum, /// half msymbol(smcircle_hollow) graph export 02matrix.emf, replace // saving the new data note: temporary dataset for st9ch2tutorial.do save sciwork, replace // closing the log log close