/* Examples of dummy variables Data " cps_msa2013 : 2013 Current population survey for 3 MSA 3 MSA : NY, LA, CHICAGO Created by Jin Man Lee Updated: 2/17/2015 */ use http://condor.depaul.edu/jlee141/econdata/cps/cps_msa2013 gen lhrwage = log(hrwage) label var lhrwage "Log of Nominal Hourly Wage" /* 1. Creating continuous education variable Number of Years of Education */ // tablulate the educ92 tab educ92 // tablulate the educ92 without label tab educ92, nolabel gen educyr = 0 replace educyr = 1 if educ92 == 1 replace educyr = 4 if educ92 == 2 replace educyr = 6 if educ92 == 3 replace educyr = 8 if educ92 == 4 replace educyr = 9 if educ92 == 5 replace educyr = 10 if educ92 == 6 replace educyr = 11 if educ92 == 7 replace educyr = 12 if educ92 == 8 | educ92 == 9 replace educyr = 14 if educ92 == 10 | educ92 == 11 | educ92 == 12 replace educyr = 16 if educ92 == 13 replace educyr = 18 if educ92 == 14 replace educyr = 20 if educ92 == 15 replace educyr = 21 if educ92 == 16 /* 2. Creating simple dummy variable Here are some examples to create simple dummy variables */ gen young = 0 replace young = 1 if age < 25 gen retired_age = age > 65 gen retired_man = (age > 65 & female == 0 ) /* 3. Creating multiple dummy variables Here are some examples to create multiple dummy variables wbho (white, black, hispanic, others) -> generate four dummy variables (race1, race2, race3, race4) */ tab wbho tab wbho, gen(race) sum race1-race4 /* 4. Regression using dummy variables aid factor variables */ regr lhrwage educyr female regr lhrwage educyr race2-race4 test race2 race3 race4 regr lhrwage educyr i.wbho predict fit1 tw (line fit1 educyr if race1 == 1 ) /// (line fit1 educyr if race2 == 1 ) /// (line fit1 educyr if race3 == 1 ) /// (line fit1 educyr if race4 == 1 ), /// legend(lab(1 "Fitted for White") lab(2 "Fitted for Black") /// lab(3 "Fitted for Hispanic") lab(4 "Fitted for Others")) /// ytitle("Fitted log of hourly wage") /// xtitle("Number of years of education") gen female_educyr = female*educyr regr lhrwage female educyr female_educyr regr lhrwage i.female##c.educyr predict fit2 tw (line fit2 educyr if female == 0) /// (line fit2 educyr if female == 1), /// legend(lab(1 "Fitted for Male") lab(2 "Fitted for Female")) /// ytitle("Fitted log of hourly wage") /// xtitle("Number of years of education")