ECONOMICS 45* -- Stata 1 Tutoral 6 Stata 1 Tutoral 6 TOPIC: Representng Mult-Category Categorcal Varables wth Dummy Varable Regressors DATA: wage1_econ45.dta (a Stata-format dataset) TASKS: Stata 1 Tutoral 6 deals wth ssues concernng the nterpretaton, testng and graphcal representaton of the condtonal/margnal effects of multcategory categorcal varables and wth dfferences n the condtonal/margnal effects of mult-category categorcal varables between two mutually exclusve populaton subgroups (e.g., males and females). It llustrates these matters n terms of a smple ln-wage regresson model for male and female employees n whch the mult-categorcal varable of nterest s ndustry of employment, as represented by a seven-category explanatory varable. The Stata commands that consttute the prmary subject of ths tutoral are: regress Used to perform OLS estmaton of multple lnear regresson models. lncom Used after estmaton to compute lnear combnatons of coeffcent estmates and assocated test statstcs. test Used to compute Wald F-tests of lnear coeffcent restrctons, wth notest and accumulate optons. return lst Used to dsplay all temporarly saved results from the most recent test or lncom command. graph bar Used to create bar graphs of the condtonal/margnal effects of a mult-category categorcal varable n lnear regresson models. graph export Exports the graph currently dsplayed n the Graph wndow to a fle n the current Stata workng drectory. margns Used after OLS estmaton to compute estmates of the condtonal and margnal effects of categorcal, or ndcator, explanatory varables. No Stata statstcal functons are used n ths tutoral. NOTE: Stata commands are case senstve. All Stata command names must be typed n the Command wndow n lower case letters. ECON 45* -- Fall 1: Stata 1 Tutoral 6 45tutoral6_f1.doc Page 1 of 5 pages
ECONOMICS 45* -- Stata 1 Tutoral 6 Preparng for Your Stata Sesson Before begnnng your Stata sesson, use Wndows Explorer to copy the Stata-format dataset wage1_econ45.dta to the Stata workng drectory on the C:-drve or D:- drve of the computer at whch you are workng. On the computers n Dunnng 35, the default Stata workng drectory s usually C:\data. On the computers n MC B111, the default Stata workng drectory s usually D:\courses. Start Your Stata Sesson To start your Stata sesson, double-clck on the Stata con on the Wndows desktop or n the Start menu under Programs. After you double-clck the Stata con, you wll see the famlar screen of four Stata wndows. Record Your Stata Sesson -- log usng To record your Stata sesson, ncludng all the Stata commands you enter and the results (output) produced by these commands, make a text-format.log fle named 45tutoral6.log. To open (begn) the log fle 45tutoral6.log, enter n the Command wndow: log usng 45tutoral6.log Ths command opens a plan text-format (ASCII) fle called 45tutoral6.log n the current Stata workng drectory. Note: It s mportant to nclude the.log fle extenson when openng a log fle; f you do not, your log fle wll be n smcl format, a format that only Stata can read. Once you have opened the 45tutoral6.log fle, a copy of all the commands you enter durng your Stata sesson and of all the results they produce s recorded n that 45tutoral6.log fle. ECON 45* -- Fall 1: Stata 1 Tutoral 6 45tutoral6_f1.doc Page of 5 pages
ECONOMICS 45* -- Stata 1 Tutoral 6 Record Only Your Stata Commands -- cmdlog usng To record only the Stata commands you type durng your Stata sesson, you can use the Stata cmdlog usng command. To start (open) the command log fle 45tutoral6.txt, enter n the Command wndow: cmdlog usng 45tutoral6 Ths command opens a plan text-format (ASCII) fle called 45tutoral6.txt n the current Stata workng drectory. All commands you enter durng your Stata sesson are recorded n ths fle. Loadng a Stata-Format Dataset nto Stata use Be certan that you have downloaded the Stata-format dataset wage1_econ45.dta from the ECON 45 course web ste, and have placed t n the Stata workng drectory. To check that the Stata-format dataset auto1.dta s n the current Stata workng drectory of the computer at whch you are workng, type n the Command wndow: dr wage1_econ45.* You should see n the Stata Results wndow the flename wage1_econ45.dta. To load, or read, nto memory the Stata-format dataset auto1.dta, type n the Command wndow: use wage1_econ45 Ths command loads nto memory the Stata-format dataset wage1_econ45.dta. To summarze the contents of the current dataset, use the descrbe and summarze commands. Type n the Command wndow the followng commands: descrbe summarze ECON 45* -- Fall 1: Stata 1 Tutoral 6 45tutoral6_f1.doc Page 3 of 5 pages
ECONOMICS 45* -- Stata 1 Tutoral 6 Model 1 Dfferent Intercepts for Male and Female Employees The dataset wage1_econ45.dta contans a bnary ndcator (dummy) varable female that dstngushes between female and male workers. The female ndcator, or dummy, varable s defned as follows: female = 1 f the -th worker s female = f the -th worker s male To see for yourself how the dummy varable female s coded, as well as how many workers n the sample are male and how many are female, enter the followng commands: codebook female tab1 female summarze female, detal In ths secton, we estmate by OLS a regresson model for the natural logarthm of employees wage rates that constrans all the slope coeffcents to be the same for male and female workers. Wrte the populaton regresson equaton for Model 1 as: ln(wage ) = β ed 1 7 exp 8 3 exp nd5 nd6 9 nd7 4 nd nd3 + δ female + u 5 6 nd4 (1) Regresson equaton (1) allows only the ntercept coeffcent to dffer between male and female workers; t restrcts all the slope coeffcents β j (j = 1,, 9) to be equal or dentcal for male and female employees. The male ntercept coeffcent s β, and the female ntercept coeffcent s β + δ ; the slope coeffcent of the female ndcator varable female s therefore the female-male dfference n ntercept coeffcents, or equvalently the female-male dfference n condtonal mean ln-wages for gven values of years of completed schoolng, potental work experence, and ndustry of employment. Frst, generate the regressand (or dependent varable) ln( wage ) n Model 1. Enter the commands: ECON 45* -- Fall 1: Stata 1 Tutoral 6 45tutoral6_f1.doc Page 4 of 5 pages
ECONOMICS 45* -- Stata 1 Tutoral 6 generate lnwage = ln(wage) summarze wage lnwage Estmate by OLS regresson equaton (1) on the full sample of 56 observatons for both female and male employees. Enter on one lne the regress command: regress lnwage ed exp expsq nd nd3 nd4 nd5 nd6 nd7 female You wll want to refer back to the OLS estmates of Model 1 produced by ths regress command, as Model 1 represents the benchmark for all subsequent models n ths tutoral. Model Dfferent Industry Effects for Male and Female Employees In ths secton, we consder a regresson model that allows not only the ntercept coeffcent, but also the set of sx ndustry slope coeffcents, to dffer between male and female employees. In other words, Model allows for dfferent ndustry effects for male and female workers, but restrcts the margnal effects of the contnuous explanatory varables ed and exp to be equal for male and female workers. Model adds to the regressors of Model 1 a set of nteractons of the female ndcator female wth each of the sx ncluded ndustry dummy varables; these female-ndustry nteracton varables are defned as follows: f = f = f = f = f = f = nd femalend nd3 femalend3 nd4 femalend4 nd5 femalend5 nd6 femalend6 nd7 femalend7 The populaton regresson equaton for Model can be wrtten as: ln(wage ) = β ed 7 6 1 + δ f nd4 8 7 exp nd5 nd6 + δ f nd5 3 9 exp nd7 8 + δ 4 + δ f nd6 nd 9 female nd3 5 + δ f nd7 + δ f nd 4 + u 6 nd4 5 + δ f nd3 () ECON 45* -- Fall 1: Stata 1 Tutoral 6 45tutoral6_f1.doc Page 5 of 5 pages
ECONOMICS 45* -- Stata 1 Tutoral 6 Before estmatng Model by OLS, you wll need to create the female-ndustry nteracton varables. Enter the followng generate commands: generate fnd = female*nd generate fnd3 = female*nd3 generate fnd4 = female*nd4 generate fnd5 = female*nd5 generate fnd6 = female*nd6 generate fnd7 = female*nd7 Interpretaton of Model : Industry base group s ndustry 1 Before proceedng to estmaton of Model, we should make sure that we understand how to nterpret the ndustry coeffcents n Model. The populaton regresson equaton for Model can be wrtten as: ln(wage ) = β ed 7 6 1 + δ f nd4 8 7 exp nd5 nd6 + δ f nd5 3 9 exp nd7 8 + δ 4 + δ f nd6 nd 9 female nd3 5 + δ f nd7 + δ f nd 4 + u 6 nd4 5 + δ f nd3 () The populaton regresson functon for Model.1 s obtaned by takng the condtonal expectaton of regresson equaton (.1) for any gven values of the four explanatory varables ed, exp, ndustry and female : E(ln(wage ) ed, exp, nd, K,nd7, female ) = β ed exp exp nd nd3 1 7 6 nd5 nd6 + δ f nd4 8 7 3 + δ f nd5 9 nd7 8 4 + δ + δ f nd6 9 5 female + δ f nd7 4 6 nd4 + δ f nd + δ f nd3 5 (*) The male populaton regresson functon mpled by Model s obtaned by settng the female ndcator varable female = n (*): E(ln(wage ) ed, exp, nd, K,nd7, female = ) ECON 45* -- Fall 1: Stata 1 Tutoral 6 45tutoral6_f1.doc Page 6 of 5 pages
ECONOMICS 45* -- Stata 1 Tutoral 6 = β ed 1 7 exp 8 3 exp nd5 nd6 9 nd7 4 nd nd3 5 6 nd4 (m) The male ndustry ntercept coeffcents are: Industry 1 ntercept coeffcent for males = β Industry ntercept coeffcent for males = β 4 Industry 3 ntercept coeffcent for males = β 5 Industry 4 ntercept coeffcent for males = β 6 Industry 5 ntercept coeffcent for males = β 7 Industry 6 ntercept coeffcent for males = β 8 Industry 7 ntercept coeffcent for males = β 9 The set of ndustry effects for male workers n Model.e., the nter-ndustry dfferences n condtonal mean ln-wages for male employees wth gven values of ed and exp are gven by the male slope coeffcents of the ndustry dummy varables nd, nd3, nd4, nd5, nd6, and nd7 that are ncluded as regressors n Model. From the ndustry ntercept coeffcents for males gven above, t follows that these male ndustry effects are: β 4 = the ndustry ndustry 1 dfference n mean ln-wages for males; β 5 = the ndustry 3 ndustry 1 dfference n mean ln-wages for males; β 6 = the ndustry 4 ndustry 1 dfference n mean ln-wages for males; β 7 = the ndustry 5 ndustry 1 dfference n mean ln-wages for males; β 8 = the ndustry 6 ndustry 1 dfference n mean ln-wages for males; β 9 = the ndustry 7 ndustry 1 dfference n mean ln-wages for males. ECON 45* -- Fall 1: Stata 1 Tutoral 6 45tutoral6_f1.doc Page 7 of 5 pages
ECONOMICS 45* -- Stata 1 Tutoral 6 The female populaton regresson functon mpled by Model s obtaned by settng the female ndcator varable female = 1 n (*): E( ln(wage ) ed, exp, nd, K,nd7, female = 1) = β ed 1 + δ 7 6 nd4 exp 8 7 3 exp nd5 nd6 9 8 nd7 4 nd + δ + δ nd5 + δ nd6 + δ 9 nd3 + δ 4 nd7 5 nd + δ 5 6 nd4 nd3 = ( β + ( β + δ ) ed 6 + δ 6 1 )nd4 + ( β exp 7 7 3 exp + ( β + δ )nd5 + ( β + δ 8 4 + δ 8 4 )nd )nd6 + ( β + ( β 9 5 + δ + δ 9 5 )nd3 )nd7 (f) The female ndustry ntercept coeffcents are: Industry 1 ntercept coeffcent for females = β + δ Industry ntercept coeffcent for females = β + δ 4 + δ 4 Industry 3 ntercept coeffcent for females = β + δ 5 + δ 5 Industry 4 ntercept coeffcent for females = β + δ 6 + δ 6 Industry 5 ntercept coeffcent for females = β + δ 7 + δ 7 Industry 6 ntercept coeffcent for females = β + δ 8 + δ 8 Industry 7 ntercept coeffcent for females = β + δ 9 + δ 9 The set of ndustry effects for female workers n Model.e., the nterndustry dfferences n condtonal mean ln-wages for female employees wth gven values of ed and exp are gven by the female slope coeffcents of the ndustry dummy varables nd, nd3, nd4, nd5, nd6, and nd7 that are ncluded as regressors n Model. From the ndustry ntercept coeffcents for females gven above, t follows that these female ndustry effects are: β 4 + δ 4 = the ndustry ndustry 1 dfference n mean ln-wages for females; β 5 + δ 5 = the ndustry 3 ndustry 1 dfference n mean ln-wages for females; β 6 + δ 6 = the ndustry 4 ndustry 1 dfference n mean ln-wages for females; β 7 + δ 7 = the ndustry 5 ndustry 1 dfference n mean ln-wages for females; β 8 + δ 8 = the ndustry 6 ndustry 1 dfference n mean ln-wages for females; β 9 + δ 9 = the ndustry 7 ndustry 1 dfference n mean ln-wages for females. ECON 45* -- Fall 1: Stata 1 Tutoral 6 45tutoral6_f1.doc Page 8 of 5 pages
ECONOMICS 45* -- Stata 1 Tutoral 6 The female-male dfferences n ndustry effects mpled by Model are obtaned by subtractng the male ndustry coeffcents (β 4, β 5, β 6, β 7, β 8 and β 9 ) from the correspondng female ndustry coeffcents (β 4 + δ 4, β 5 + δ 5, β 6 + δ 6, β 7 + δ 7, β 8 + δ 8 and β 9 + δ 9 ).e., by the slope coeffcents δ 4, δ 5, δ 6, δ 7, δ 8, and δ 9 of the female-ndustry nteracton terms f nd, f nd3, f nd4, f nd5, f nd6, and f nd7 n Model. For ndustry : β 4 + δ 4 = the ndustry ndustry 1 dfference n mean ln-wages for females β 4 = the ndustry ndustry 1 dfference n mean ln-wages for males Therefore δ 4 = the ndustry ndustry 1 dfference n mean ln-wages for females mnus the ndustry ndustry 1 dfference n mean ln-wages for males Smlarly, for ndustres 3, 4, 5, 6 and 7: δ 5 = the ndustry 3 ndustry 1 dfference n mean ln-wages for females mnus the ndustry 3 ndustry 1 dfference n mean ln-wages for males δ 6 = the ndustry 4 ndustry 1 dfference n mean ln-wages for females mnus the ndustry 4 ndustry 1 dfference n mean ln-wages for males δ 7 = the ndustry 5 ndustry 1 dfference n mean ln-wages for females mnus the ndustry 5 ndustry 1 dfference n mean ln-wages for males δ 8 = the ndustry 6 ndustry 1 dfference n mean ln-wages for females mnus the ndustry 6 ndustry 1 dfference n mean ln-wages for males ECON 45* -- Fall 1: Stata 1 Tutoral 6 45tutoral6_f1.doc Page 9 of 5 pages
ECONOMICS 45* -- Stata 1 Tutoral 6 δ 9 = the ndustry 7 ndustry 1 dfference n mean ln-wages for females mnus the ndustry 7 ndustry 1 dfference n mean ln-wages for males Note that the condtonal effects of ndustry on mean ln-wages are dentcal or equal for male and female workers f the regresson coeffcents δ 4, δ 5, δ 6, δ 7, δ 8 and δ 9 are jontly equal to zero:.e., f δ 4 = δ 5 = δ 6 = δ 7 = δ 8 = δ 9 =, or f δ j = for all j = 4, 5,, 9. OLS Estmaton of Model Estmate Model by OLS on the full sample of 56 female and male employees. Enter on one lne the regress command: regress lnwage ed exp expsq nd nd3 nd4 nd5 nd6 nd7 female fnd fnd3 fnd4 fnd5 fnd6 fnd7 Use lncom commands to compute and test the female ntercept coeffcent estmate and the female coeffcent estmates for the ndustry dummy varables nd, nd3, nd4, nd5, nd6, and nd7 n Model. Enter the followng seres of lncom commands: + δˆ + δˆ + δˆ + δˆ + δˆ + δˆ + δˆ lncom _b[_cons] + _b[female] = lncom _b[nd] + _b[fnd] = 4 4 lncom _b[nd3] + _b[fnd3] = 5 5 lncom _b[nd4] + _b[fnd4] = 6 6 lncom _b[nd5] + _b[fnd5] = 7 7 lncom _b[nd6] + _b[fnd6] = 8 8 lncom _b[nd7] + _b[fnd7] = 9 9 βˆ βˆ βˆ βˆ βˆ βˆ βˆ ECON 45* -- Fall 1: Stata 1 Tutoral 6 45tutoral6_f1.doc Page 1 of 5 pages
ECONOMICS 45* -- Stata 1 Tutoral 6 Test for Industry Effects n Model We now wsh to test for ndustry effects n Model. There are three such tests that should be performed. Industry Effects Test 1: Test for ndustry effects for male employees Test the null hypothess of no ndustry effects for male employees n Model. Snce ndustry effects for males n Model are represented by the male slope coeffcents β 4, β 5, β 6, β 7, β 8 and β 9 of the ndustry dummy varables nd, nd3, nd4, nd5, nd6, and nd7, the null and alternatve hypotheses are specfed as follows: H : β j = for all j = 4, 5,, 9; or β 4 = and β 5 = and β 6 = and β 7 = and β 8 = and β 9 = H 1 : β j j = 4, 5,, 9; or β 4 and/or β 5 and/or β 6 and/or β 7 and/or β 8 and/or β 9 Use the followng test command to compute an F-test of the null hypothess of no ndustry effects for male employees. Enter the commands: test nd nd3 nd4 nd5 nd6 nd7 return lst Based on the computed outcome of ths test, would you retan or reject the null hypothess of no ndustry effects for male workers? Industry Effects Test : Test for ndustry effects for female employees Test the null hypothess of no ndustry effects for female employees n Model. Snce ndustry effects for females n Model are represented by the female slope coeffcents β 4 + δ 4, β 5 + δ 5, β 6 + δ 6, β 7 + δ 7, β 8 + δ 8 and β 9 + δ 9 of the ndustry dummy varables nd, nd3, nd4, nd5, nd6, and nd7 n the female ln-wage regresson functon, the null and alternatve hypotheses are specfed as follows: ECON 45* -- Fall 1: Stata 1 Tutoral 6 45tutoral6_f1.doc Page 11 of 5 pages
ECONOMICS 45* -- Stata 1 Tutoral 6 H : β j + δ j = for all j = 4, 5,, 9; or β 4 + δ 4 = and β 5 + δ 5 = and β 6 + δ 6 = and β 7 + δ 7 = and β 8 + δ 8 = and β 9 + δ 9 = H 1 : β j + δ j j = 4, 5,, 9; or β 4 + δ 4 and/or β 5 + δ 5 and/or β 6 + δ 6 and/or β 7 + δ 7 and/or β 8 + δ 8 and/or β 9 + δ 9 Use the followng seres of lnked test commands to compute an F-test of the null hypothess of no ndustry effects for female employees. Enter the commands: test nd + fnd =, notest test nd3 + fnd3 =, notest accumulate test nd4 + fnd4 =, notest accumulate test nd5 + fnd5 =, notest accumulate test nd6 + fnd6 =, notest accumulate test nd7 + fnd7 =, accumulate return lst Note that only the results produced by the last of ths sequence of sx test commands correspond to the null hypothess H of no ndustry effects for female workers. That s why the notest opton has been specfed for the frst fve test commands n ths sequence; the notest opton smply suppresses the prntng of the results of the test command to whch t s attached. Based on the computed outcome of ths test, would you retan or reject the null hypothess of no ndustry effects for female workers? Industry Effects Test 3: Test for female-male dfferences n ndustry effects Test the null hypothess of no female-male dfferences n ndustry effects n Model. Snce the female-male dfferences n ndustry effects n Model are represented by the slope coeffcents δ 4, δ 5, δ 6, δ 7, δ 8 and δ 9 of the female nteractons wth the ndustry dummy varables nd, nd3, nd4, nd5, nd6, and nd7 n Model, the null and alternatve hypotheses are specfed as follows: ECON 45* -- Fall 1: Stata 1 Tutoral 6 45tutoral6_f1.doc Page 1 of 5 pages
ECONOMICS 45* -- Stata 1 Tutoral 6 H : δ j = for all j = 4, 5,, 9; or δ 4 = and δ 5 = and δ 6 = and δ 7 = and δ 8 = and δ 9 = H 1 : δ j j = 4, 5,, 9; or δ 4 and/or δ 5 and/or δ 6 and/or δ 7 and/or δ 8 and/or δ 9 Use the followng test command to compute an F-test of the null hypothess of no female-male dfferences n ndustry effects n Model,.e., that ndustry effects are equal, or dentcal, for male and female employees. Enter the commands: test fnd fnd3 fnd4 fnd5 fnd6 fnd7 return lst Based on the computed outcome of ths test, would you retan or reject the null hypothess of no ndustry effects for male workers? Note: If you have correctly computed the foregong test of no female-male dfferences n ndustry effects n Model, you wll have found that the null hypothess H s retaned at all conventonal sgnfcance levels. Despte ths test outcome, we wll, for pedagogcal reasons, proceed wth learnng how Stata graph bar commands can be used to graphcally llustrate the male and female ndustry effects n Model. But bear n mnd that ths test mples that ndustry effects n Model do not dffer sgnfcantly between male and female workers. Industry Effects n Model for Male and Female Employees margns In ths secton, we demonstrate how the Stata margns command, to whch you were ntroduced n Stata 1 Tutoral 4, can be used to compute for Model ndustry effects for male and female employees and female-male dfferences n ndustry effects. Frst, re-estmate Model by OLS usng factor-varable notaton to dstngush between contnuous and categorcal explanatory varables n the regress command. Recall from Stata 1 Tutoral 4 that the c. prefx must precede the name of each contnuous explanatory varable, whle the. prefx must precede the name of each contnuous explanatory varable. Enter on one lne the command: ECON 45* -- Fall 1: Stata 1 Tutoral 6 45tutoral6_f1.doc Page 13 of 5 pages
ECONOMICS 45* -- Stata 1 Tutoral 6 regress lnwage c.ed c.exp c.exp#c.exp.ndustry.female.female#.ndustry Use the margns command to compute the condtonal mean values of ln(wage ) at the sample medan values of ed and exp for male and female employees n the seven ndustry categores. Enter the followng two margns commands, and observe that they yeld dentcal results: margns.ndustry, at((medan) ed exp female = ( 1)) margns.female, at((medan) ed exp ndustry = (1(1)7)) Now use the margns command to compute female-male dfferences n the condtonal mean values of ln(wage ) at the sample medan values of ed and exp for each of the seven ndustry categores. Enter the followng two margns commands, and observe that they yeld dentcal results: margns r.female, at((medan) ed exp ndustry = (1(1)7)) margns r.female, over(ndustry) at(ed = 1 exp = 13.5) Note that the second margns command that uses the over(ndustry) opton must specfy the numercal values of ed and exp n order to produce the ntended results. In the two prevous margns commands, t s not necessary to specfy the sample values of ed and exp n computng female-male dfferences n the condtonal mean values of ln(wage ) for each of the seven ndustry categores. Ths s so because Model restrcts the regresson coeffcents of the ed and exp regressors to be the same for male and female employees. To verfy ths, enter the followng two margns commands and observe that they produce results dentcal to those of the two prevous margns commands that specfy the medan values of ed and exp: margns r.female, at(ndustry = (1(1)7)) margns r.female, over(ndustry) ECON 45* -- Fall 1: Stata 1 Tutoral 6 45tutoral6_f1.doc Page 14 of 5 pages
ECONOMICS 45* -- Stata 1 Tutoral 6 Next, use the margns command to compute separately for male and female employees nter-ndustry dfferences n the condtonal mean values of ln(wage ) relatve to Industry 1 (the base group ndustry). Note that t s not necessary to specfy the values of ed and exp to be used, because the parwse ndustry dfferences n condtonal mean ln(wage ) values do not depend on, or vary wth, the contnuous explanatory varables ed and exp; they depend only on the categorcal varable female. Enter the followng four margns commands, and observe that they yeld dentcal results: margns r.ndustry, over(female) margns r.ndustry, over(female) at(ed = 1 exp = 13.5) margns r.ndustry, at(female = ( 1)) margns r.ndustry, at((medan) ed exp female = ( 1)) Fnally, suppose we wsh to use Industry 4 rather than Industry 1 as the base group for purposes of computng the nter-ndustry dfferences n the condtonal mean values of ln(wage ) for male and female employees. That s, we wsh to compute dfferences n the condtonal mean values of ln(wage ) for ndustres 1,, 3, 5, 6, and 7 relatve to Industry 4. Ths can be easly done by smply changng the r. prefx on ndustry n the precedng margns commands to rb4.. The rb4. prefx nstructs Stata to use the fourth smallest value of the categorcal varable ndustry as the base group, rather than the smallest value, whch s the default mpled by the r. prefx. Enter the followng four margns commands, and observe that they yeld dentcal results: margns rb4.ndustry, over(female) margns rb4.ndustry, over(female) at(ed = 1 exp = 13.5) margns rb4.ndustry, at(female = ( 1)) margns rb4.ndustry, at((medan) ed exp female = ( 1)) Model -- Graphng Industry Effects for Male and Female Employees Ths secton demonstrates how to use the Stata graph bar command to graphcally llustrate the male and female ndustry effects we have estmated for Model. Before we can use the graph bar command, we must save the male and female ndustry coeffcent estmates for Model n a form that can be used n the graph bar command. ECON 45* -- Fall 1: Stata 1 Tutoral 6 45tutoral6_f1.doc Page 15 of 5 pages
ECONOMICS 45* -- Stata 1 Tutoral 6 Step 1: Generate a new varable that contans the values of the male ndustry coeffcent estmates for Model ;.e., create a varable that contans the OLS estmates for Model of the male coeffcents for the ndustry dummy varables nd, nd3, nd4, nd5, nd6, and nd7 n Model. Use the followng seres of generate and replace commands to create a new varable named malndcoefs_model that contans the OLS coeffcent estmates for Model of the male slope coeffcents β 4, β 5, β 6, β 7, β 8 and β 9 of the ndustry dummy varables nd, nd3, nd4, nd5, nd6, and nd7. Enter the followng seres of generate and replace commands: generate malndcoefs_model = _b[nd] f nd == 1 & female == replace malndcoefs_model = _b[nd3] f nd3 == 1 & female == replace malndcoefs_model = _b[nd4] f nd4 == 1 & female == replace malndcoefs_model = _b[nd5] f nd5 == 1 & female == replace malndcoefs_model = _b[nd6] f nd6 == 1 & female == replace malndcoefs_model = _b[nd7] f nd7 == 1 & female == Next, we should verfy that the varable malndcoefs_model we have just created does ndeed contan the OLS coeffcent estmates for Model of the male slope coeffcents β 4, β 5, β 6, β 7, β 8 and β 9 of the ndustry dummy varables nd, nd3, nd4, nd5, nd6, and nd7. Enter the followng seres of summarze commands: summarze malndcoefs_model f nd == 1 & female == summarze malndcoefs_model f nd3 == 1 & female == summarze malndcoefs_model f nd4 == 1 & female == summarze malndcoefs_model f nd5 == 1 & female == summarze malndcoefs_model f nd6 == 1 & female == summarze malndcoefs_model f nd7 == 1 & female == Fnally, enter the followng tab1 commands: tab1 ndustry malndcoefs_model, mssng tab1 ndustry malndcoefs_model table ndustry, contents(mean malndcoefs_model) ECON 45* -- Fall 1: Stata 1 Tutoral 6 45tutoral6_f1.doc Page 16 of 5 pages
ECONOMICS 45* -- Stata 1 Tutoral 6 Step : Generate a new varable that contans the values of the female ndustry coeffcent estmates for Model ;.e., create a varable that contans the OLS estmates for Model of the female coeffcents for the ndustry dummy varables nd, nd3, nd4, nd5, nd6, and nd7 n Model. Use the followng seres of generate and replace commands to create a new varable named femndcoefs_model that contans the OLS coeffcent estmates for Model of the female slope coeffcents β 4 + δ 4, β 5 + δ 5, β 6 + δ 6, β 7 + δ 7, β 8 + δ 8 and β 9 + δ 9 of the ndustry dummy varables nd, nd3, nd4, nd5, nd6, and nd7. Enter the followng seres of generate and replace commands: generate femndcoefs_model = _b[nd] + _b[fnd] f nd == 1 & female == 1 replace femndcoefs_model = _b[nd3] + _b[fnd3] f nd3 == 1 & female == 1 replace femndcoefs_model = _b[nd4] + _b[fnd4] f nd4 == 1 & female == 1 replace femndcoefs_model = _b[nd5] + _b[fnd5] f nd5 == 1 & female == 1 replace femndcoefs_model = _b[nd6] + _b[fnd6] f nd6 == 1 & female == 1 replace femndcoefs_model = _b[nd7] + _b[fnd7] f nd7 == 1 & female == 1 Next, verfy that the varable femndcoefs_model we have just created does ndeed contan the OLS coeffcent estmates for Model of the female slope coeffcents β 4 + δ 4, β 5 + δ 5, β 6 + δ 6, β 7 + δ 7, β 8 + δ 8 and β 9 + δ 9 of the ndustry dummy varables nd, nd3, nd4, nd5, nd6, and nd7. Enter the followng seres of summarze commands: summarze femndcoefs_model f nd == 1 & female == 1 summarze femndcoefs_model f nd3 == 1 & female == 1 summarze femndcoefs_model f nd4 == 1 & female == 1 summarze femndcoefs_model f nd5 == 1 & female == 1 summarze femndcoefs_model f nd6 == 1 & female == 1 summarze femndcoefs_model f nd7 == 1 & female == 1 Fnally, enter the followng tab1 commands: ECON 45* -- Fall 1: Stata 1 Tutoral 6 45tutoral6_f1.doc Page 17 of 5 pages
ECONOMICS 45* -- Stata 1 Tutoral 6 tab1 ndustry femndcoefs_model, mssng tab1 ndustry femndcoefs_model table ndustry, contents(mean femndcoefs_model) table ndustry, contents(mean malndcoefs_model mean femndcoefs_model) Step 3: We can now use the newly created varables malndcoefs_model and femndcoefs_model to draw a bar graph of the estmated male and female ndustry effects n Model. Use the followng basc graph bar command to create a frst bar graph of the estmated male and female ndustry effects n Model. Enter on one lne the graph bar command: graph bar (mean) malndcoefs_model femndcoefs_model f ndustry > 1, over(ndustry) We can produce a more complete and nformatve bar graph by addng to the above graph bar command some addtonal optons that label the bars as Male or Female, that provde a ttle for the vertcal y-axs, and that provde a ttle for the entre graph. Enter on one lne the followng expanded graph bar command: graph bar (mean) malndcoefs_model femndcoefs_model f ndustry > 1, over(ndustry) legend ( label(1 "Male") label( "Female") ) yttle("mean ndustry ln-wage dfference" "relatve to ndustry 1 (log ponts)") ttle("mean Ln-Wage Dfferences Relatve to Industry 1," "Industres to 7 by Gender -- Model ") Carefully observe how the graph bar optons legend, yttle and ttle have been used to provde a more fnshed and complete bar graph. To export and save ths bar graph n Wndows Enhanced Metafle format to a fle named bargraph1_tutoral6.emf n the current Stata workng drectory, enter the graph export command: graph export bargraph1_tutoral6.emf ECON 45* -- Fall 1: Stata 1 Tutoral 6 45tutoral6_f1.doc Page 18 of 5 pages
ECONOMICS 45* -- Stata 1 Tutoral 6 Here s what the bar graph you just exported n Wndows Enhanced Metafle format to the fle bargraph1_tutoral6.emf looks lke when t s nserted nto ths MS Word document: Mean Ln-Wage Dfferences Relatve to Industry 1, Industres to 7 by Gender, Model mean ndustry ln-wage dfference relatve to ndustry 1 (log ponts) -.4 -.3 -. -.1 Industry Industry 3 Industry 4 Industry 5 Industry 6 Industry 7 Male Female You can produce a horzontal verson of the bar graph you have just created by usng the graph hbar command rather than the graph bar command. Enter the followng expanded graph hbar command: graph hbar (mean) malndcoefs_model femndcoefs_model f ndustry > 1, over(ndustry) legend ( label(1 "Male") label( "Female") ) yttle("mean ndustry ln-wage dfference" "relatve to ndustry 1 (log ponts)") ttle("mean Ln-Wage Dfferences Relatve to Industry 1," "Industres to 7 by Gender -- Model ") Note that the above command s dentcal to the graph bar command on the prevous page except for the use of the graph hbar command. Agan observe how the graph hbar optons legend, yttle and ttle have been used to provde a more fnshed and complete bar graph. ECON 45* -- Fall 1: Stata 1 Tutoral 6 45tutoral6_f1.doc Page 19 of 5 pages
ECONOMICS 45* -- Stata 1 Tutoral 6 To export and save ths bar graph n Wndows Enhanced Metafle format to a fle named bargraph_tutoral6.emf n the current Stata workng drectory, enter the graph export command: graph export bargraph_tutoral6.emf Here s what the horzontal bar graph you just exported n Wndows Enhanced Metafle format to the fle bargraph_tutoral6.emf looks lke when t s nserted nto ths MS Word document: Mean Ln-Wage Dfferences Relatve to Industry 1, Industres to 7 by Gender, Model Industry Industry 3 Industry 4 Industry 5 Industry 6 Industry 7 -.4 -.3 -. -.1 mean ndustry ln-wage dfference relatve to ndustry 1 (log ponts) Male Female ECON 45* -- Fall 1: Stata 1 Tutoral 6 45tutoral6_f1.doc Page of 5 pages
ECONOMICS 45* -- Stata 1 Tutoral 6 A Thrd Bar Graph Depctng the Industry Effects for Males and Females Fnally, we can use an alternatve graph hbar command to create a second horzontal bar graph that depcts the ndustry effects for male and female workers estmated n Model. But frst we must save the male and female ndustry coeffcent estmates for Model n a form that can be used n the graph hbar command. Step 1: Generate a new varable that contans the values of the male ndustry coeffcent estmates for Model ;.e., create a varable that contans the OLS estmates for Model of the male coeffcents for the ndustry dummy varables nd, nd3, nd4, nd5, nd6, and nd7 n Model. Use the followng seres of generate and replace commands to create a new varable named allndcoefs_model that contans the OLS coeffcent estmates for Model of both the male slope coeffcents β 4, β 5, β 6, β 7, β 8 and β 9 of the ndustry dummy varables nd, nd3, nd4, nd5, nd6, and nd7 and the female slope coeffcents β 4 + δ 4, β 5 + δ 5, β 6 + δ 6, β 7 + δ 7, β 8 + δ 8 and β 9 + δ 9 of the ndustry dummy varables nd, nd3, nd4, nd5, nd6, and nd7. Enter the followng seres of generate and replace commands: generate allndcoefs_model = _b[nd] f nd == 1 & female == replace allndcoefs_model = _b[nd3] f nd3 == 1 & female == replace allndcoefs_model = _b[nd4] f nd4 == 1 & female == replace allndcoefs_model = _b[nd5] f nd5 == 1 & female == replace allndcoefs_model = _b[nd6] f nd6 == 1 & female == replace allndcoefs_model = _b[nd7] f nd7 == 1 & female == replace allndcoefs_model = _b[nd] + _b[fnd] f nd == 1 & female == 1 replace allndcoefs_model = _b[nd3] + _b[fnd3] f nd3 == 1 & female == 1 replace allndcoefs_model = _b[nd4] + _b[fnd4] f nd4 == 1 & female == 1 replace allndcoefs_model = _b[nd5] + _b[fnd5] f nd5 == 1 & female == 1 ECON 45* -- Fall 1: Stata 1 Tutoral 6 45tutoral6_f1.doc Page 1 of 5 pages
ECONOMICS 45* -- Stata 1 Tutoral 6 replace allndcoefs_model = _b[nd6] + _b[fnd6] f nd6 == 1 & female == 1 replace allndcoefs_model = _b[nd7] + _b[fnd7] f nd7 == 1 & female == 1 Next, verfy that the varable allndcoefs_model we have just created does ndeed contan the OLS coeffcent estmates for Model of both the male slope coeffcents β 4, β 5, β 6, β 7, β 8 and β 9 and the female slope coeffcents β 4 + δ 4, β 5 + δ 5, β 6 + δ 6, β 7 + δ 7, β 8 + δ 8 and β 9 + δ 9 of the ndustry dummy varables nd, nd3, nd4, nd5, nd6, and nd7. Enter the followng seres of summarze commands: summarze allndcoefs_model f nd == 1 & female == summarze allndcoefs_model f nd3 == 1 & female == summarze allndcoefs_model f nd4 == 1 & female == summarze allndcoefs_model f nd5 == 1 & female == summarze allndcoefs_model f nd6 == 1 & female == summarze allndcoefs_model f nd7 == 1 & female == summarze allndcoefs_model f nd == 1 & female == 1 summarze allndcoefs_model f nd3 == 1 & female == 1 summarze allndcoefs_model f nd4 == 1 & female == 1 summarze allndcoefs_model f nd5 == 1 & female == 1 summarze allndcoefs_model f nd6 == 1 & female == 1 summarze allndcoefs_model f nd7 == 1 & female == 1 Fnally, enter the followng tab1 and tab commands: tab1 ndustry allndcoefs_model f female ==, mssng tab1 ndustry allndcoefs_model f female == 1, mssng tab allndcoefs_model female, mssng tab ndustry female, mssng Careful nspecton of the results of these tab1 and tab commands wll enable you to verfy that the newly created varable allndcoefs_model does ndeed contan the OLS coeffcent estmates for Model of both the male slope coeffcents β 4, β 5, β 6, β 7, β 8 and β 9 and the female slope coeffcents β 4 + δ 4, β 5 + δ 5, β 6 + δ 6, β 7 + δ 7, β 8 + δ 8 and β 9 + δ 9 of the ndustry dummy varables nd, nd3, nd4, nd5, nd6, and nd7. ECON 45* -- Fall 1: Stata 1 Tutoral 6 45tutoral6_f1.doc Page of 5 pages
ECONOMICS 45* -- Stata 1 Tutoral 6 Step : We can now use the newly created varable allndcoefs_model to draw a horzontal bar graph of the estmated male and female ndustry effects n Model. Use the followng basc graph hbar command to create a frst horzontal bar graph of the estmated male and female ndustry effects n Model. Enter the graph bar command: graph hbar (mean) allndcoefs_model f ndustry > 1, over(female) over(ndustry) Note that the above graph hbar command ncludes both the over(female) and the over(ndustry) optons. We can produce a more complete and nformatve bar graph by addng to the above graph hbar command some addtonal optons that provde a ttle for the vertcal y-axs, and that provde a ttle for the entre graph. Enter the followng expanded graph hbar command: graph hbar (mean) allndcoefs_model f ndustry > 1, over(female) over(ndustry) yttle("mean ndustry ln-wage dfference" "relatve to ndustry 1 (log ponts)") ttle("mean Ln-Wage Dfferences Relatve to Industry 1," "Industres to 7 by Gender, Model ", span) Note that the opton span s specfed n the ttle( ) porton of the above graph hbar command; t centers the ttle over the entre graph rather than over the plot regon. To export and save ths bar graph n Wndows Enhanced Metafle format to a fle named bargraph3_tutoral6.emf n the current Stata workng drectory, enter the graph export command: graph export bargraph3_tutoral6.emf ECON 45* -- Fall 1: Stata 1 Tutoral 6 45tutoral6_f1.doc Page 3 of 5 pages
ECONOMICS 45* -- Stata 1 Tutoral 6 Here s what the horzontal bar graph you just exported n Wndows Enhanced Metafle format to the fle bargraph3_tutoral6.emf looks lke when t s nserted nto ths MS Word document: Mean Ln-Wage Dfferences Relatve to Industry 1, Industres to 7 by Gender, Model Industry Industry 3 Industry 4 Industry 5 Industry 6 Industry 7 Male Female Male Female Male Female Male Female Male Female Male Female -.4 -.3 -. -.1 mean ndustry ln-wage dfference relatve to ndustry 1 (log ponts) ECON 45* -- Fall 1: Stata 1 Tutoral 6 45tutoral6_f1.doc Page 4 of 5 pages
ECONOMICS 45* -- Stata 1 Tutoral 6 Preparng to End Your Stata Sesson Before you end your Stata sesson, you should do two thngs. Frst, you wll probably want to save the current dataset. Enter the followng save command wth the replace opton to save the current dataset as Stata-format dataset wage1_econ45.dta: save wage1_econ45, replace Second, close the log fle you have been recordng. Enter the command: log close Fnally, close the command log fle you have been recordng. Enter the command: cmdlog close End Your Stata Sesson -- ext To end your Stata sesson, use the ext command. Enter the command: ext or ext, clear Cleanng Up and Clearng Out After returnng to Wndows, you should copy all the fles you have used and created durng your Stata sesson to your own portable electronc storage devce such as a flash memory stck. These fles wll be found n the Stata workng drectory, whch s usually C:\data on the computers n Dunnng 35. There are three fles you wll want to be sure you have: the complete Stata log fle 45tutoral6.log; the Stata command log fle 45tutoral6.txt; and the changed Stata-format dataset wage1_econ45.dta. Use the Wndows copy command to copy any fles you want to keep to your own portable electronc storage devce (e.g., a flash memory stck). Fnally, as a courtesy to other users of the computng classroom, please delete all the fles you have used or created from the Stata workng drectory. ECON 45* -- Fall 1: Stata 1 Tutoral 6 45tutoral6_f1.doc Page 5 of 5 pages