* Examples of dummy independent variables Data " cps_msa2013 : 2013 Current population survey for 3 MSA 3 MSA : NY, LA, CHICAGO */ use https://bigblue.depaul.edu/jlee141/econdata/cps_data/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 ) \end{lstlisting} \end{column} \begin{column}{0.5\textwidth} \begin{lstlisting}[basicstyle=\tiny] /* 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 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")) /// legend(lab(3 "Fitted for Hispanic") lab(4 "Fitted for Others")) /// ytitle("Fitted log of hourly wage") /// xtitle("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("years of education") /* Functional Forms in Regression Model */ /* House Price in Chicago (zip == 60629) */ clear all use https://bigblue.depaul.edu/jlee141/econdata/hp2013chi.dta keep if zip == 60629 gen log_hprice = log(hprice*1000) gen log_sqft = log(sqft) gen price = hprice*1000 /* Linear Model */ regr price sqft /* Log-Linear Model */ regr log_hprice sqft /* Linear-Log Model */ regr price log_sqft /* Double Log Model */ regr log_hprice log_sqft /* Nonlinear Relationship between wage and eductions */ clear all use https://bigblue.depaul.edu/jlee141/econdata/wage1 tw ( scatter wage educ) (lfit wage educ) (qfit wage educ) regr wage educ regr wage educ educ_sq