I now face a problem in dealing with drawing a combined graph with adding a legend to one [Either the first or the last is ok] of them. My code and simulation data are as follows:
Code:
local i=1 foreach var in yedu male exp exp2 marriage public technical selfem lnseadis service invshare lnpd{ tw (rarea _lb_ _ub_ q if var=="`var'" & year==2005, astyle(ci) legend(off) acolor(%10)) /// (line _b_ q if var=="`var'" & year==2005, lp(solid) lc(black) lwidth(medthick)) /// (line _b_ q if var=="`var'" & year==2017, lp(dash) lc(black) lwidth(medthick)) /// (rarea _lb_ _ub_ q if var=="`var'" & year==2017, astyle(ci) legend(off) acolor(%70)) /// , ylabel(,grid) legend(off) xtitle("") ytitle("`var'") xlab(10(10)90) graph save `i'.gph,replace local `i++' } forvalues i=1/12{ local j `j' `i'.gph } graph combine `j', rows(3) xcommon b1title(Quantile) xsize(20) ysize(15)
Code:
legend(order(1 "" 2 "Year=2005" 3 "" 4 "Year=2017"))
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input double q str9 var double(_b_ _lb_ _ub_ year) 10 "exp" .7060326085590829 .6060326085590829 .8060326085590829 2017 10 "exp2" .726402675659736 .6264026756597361 .826402675659736 2017 10 "invshare" -.5658946129590842 -.6658946129590841 -.4658946129590842 2017 10 "lnpd" .5519959561074571 .45199595610745713 .6519959561074571 2017 10 "lnseadis" -.18153243202494282 -.2815324320249428 -.08153243202494281 2017 10 "male" -.0845013554436748 -.1845013554436748 .0154986445563252 2017 10 "marriage" -.4041389284762828 -.5041389284762828 -.30413892847628277 2017 10 "public" .020004355394671065 -.07999564460532894 .12000435539467107 2017 10 "selfem" .48433854112936714 .38433854112936716 .5843385411293671 2017 10 "service" -.7991442906253145 -.8991442906253144 -.6991442906253145 2017 10 "technical" .9090786318579027 .8090786318579027 1.0090786318579028 2017 10 "yedu" -1.9924347702665213 -2.092434770266521 -1.8924347702665212 2017 20 "exp" 1.0829853467028185 .9829853467028186 1.1829853467028186 2017 20 "exp2" -.16090842717953516 -.26090842717953516 -.06090842717953515 2017 20 "invshare" .30674478942922984 .20674478942922983 .40674478942922987 2017 20 "lnpd" -.5065183852493573 -.6065183852493573 -.40651838524935735 2017 20 "lnseadis" -.43572051644296983 -.5357205164429698 -.33572051644296985 2017 20 "male" 1.651875636929618 1.5518756369296178 1.751875636929618 2017 20 "marriage" -.6447973998713261 -.7447973998713261 -.5447973998713261 2017 20 "public" -.4175254237175186 -.5175254237175186 -.3175254237175186 2017 20 "selfem" 2.0411698908918843 1.9411698908918842 2.1411698908918844 2017 20 "service" .06722946758118882 -.032770532418811185 .16722946758118884 2017 20 "technical" .7322509269000815 .6322509269000816 .8322509269000815 2017 20 "yedu" 1.5519754699023833 1.4519754699023832 1.6519754699023834 2017 30 "exp" -.9745130346488835 -1.0745130346488836 -.8745130346488835 2017 30 "exp2" -.5929022500919842 -.6929022500919841 -.4929022500919842 2017 30 "invshare" -.04031543219538614 -.14031543219538614 .05968456780461386 2017 30 "lnpd" -1.2118245071664837 -1.3118245071664838 -1.1118245071664836 2017 30 "lnseadis" -1.2209557864199687 -1.3209557864199688 -1.1209557864199686 2017 30 "male" .6098041899993792 .5098041899993793 .7098041899993792 2017 30 "marriage" 1.21755898947616 1.11755898947616 1.3175589894761601 2017 30 "public" -.6499796163777138 -.7499796163777138 -.5499796163777139 2017 30 "selfem" .19196218557171718 .09196218557171718 .29196218557171716 2017 30 "service" -.0034875439349294104 -.10348754393492941 .0965124560650706 2017 30 "technical" .5933717454929767 .4933717454929767 .6933717454929766 2017 30 "yedu" -3.1938794302683875 -3.2938794302683876 -3.0938794302683874 2017 40 "exp" -1.2075545364948739 -1.307554536494874 -1.1075545364948738 2017 40 "exp2" -1.9497608851450245 -2.0497608851450244 -1.8497608851450245 2017 40 "invshare" -1.0852834880823283 -1.1852834880823284 -.9852834880823284 2017 40 "lnpd" 1.2278354438237018 1.1278354438237017 1.3278354438237019 2017 40 "lnseadis" -.08949357837845028 -.18949357837845027 .01050642162154973 2017 40 "male" -.7817259898991239 -.8817259898991239 -.6817259898991239 2017 40 "marriage" -.006298525444925158 -.10629852544492516 .09370147455507485 2017 40 "public" .5736665843136239 .47366658431362396 .6736665843136239 2017 40 "selfem" -.3752464572498259 -.47524645724982595 -.2752464572498259 2017 40 "service" 1.2438163623197571 1.143816362319757 1.3438163623197572 2017 40 "technical" -.5654756492131274 -.6654756492131274 -.46547564921312745 2017 40 "yedu" -1.2650579569018414 -1.3650579569018415 -1.1650579569018413 2017 50 "exp" -.2365498864312237 -.33654988643122374 -.1365498864312237 2017 50 "exp2" .32974943774979143 .22974943774979142 .42974943774979146 2017 50 "invshare" -1.8187317179648683 -1.9187317179648684 -1.7187317179648682 2017 50 "lnpd" .18099392257039001 .08099392257039001 .28099392257039 2017 50 "lnseadis" -.3677759766603274 -.46777597666032744 -.2677759766603274 2017 50 "male" -.6410358243192722 -.7410358243192722 -.5410358243192722 2017 50 "marriage" -1.1088816736197935 -1.2088816736197936 -1.0088816736197934 2017 50 "public" -2.7357945990952226 -2.8357945990952227 -2.6357945990952225 2017 50 "selfem" -.4734398368242343 -.5734398368242343 -.3734398368242343 2017 50 "service" -.9467615933164374 -1.0467615933164374 -.8467615933164374 2017 50 "technical" 2.4852312200608773 2.385231220060877 2.5852312200608774 2017 50 "yedu" -.9572937265254512 -1.0572937265254512 -.8572937265254512 2017 60 "exp" .3710736268929003 .27107362689290027 .47107362689290033 2017 60 "exp2" -1.951609032388604 -2.051609032388604 -1.8516090323886039 2017 60 "invshare" -.9805115295034632 -1.0805115295034633 -.8805115295034632 2017 60 "lnpd" .7717659733708064 .6717659733708065 .8717659733708064 2017 60 "lnseadis" .6700023387393872 .5700023387393872 .7700023387393872 2017 60 "male" -.45933323251556496 -.559333232515565 -.3593332325155649 2017 60 "marriage" 1.0865013213712056 .9865013213712056 1.1865013213712057 2017 60 "public" -1.022195441348625 -1.122195441348625 -.922195441348625 2017 60 "selfem" .08064687391805621 -.019353126081943797 .18064687391805623 2017 60 "service" 1.2051993292555434 1.1051993292555433 1.3051993292555435 2017 60 "technical" -.0013385085247690181 -.10133850852476903 .09866149147523098 2017 60 "yedu" -.02403024380600702 -.12403024380600702 .07596975619399299 2017 70 "exp" -.24799516564594717 -.3479951656459472 -.14799516564594717 2017 70 "exp2" -2.1129778707936158 -2.212977870793616 -2.0129778707936157 2017 70 "invshare" .636780454799782 .536780454799782 .7367804547997819 2017 70 "lnpd" .9070299072318028 .8070299072318028 1.0070299072318027 2017 70 "lnseadis" -1.2069927673694567 -1.3069927673694568 -1.1069927673694566 2017 70 "male" .022509918628805206 -.0774900813711948 .12250991862880521 2017 70 "marriage" .5330289169453144 .4330289169453144 .6330289169453144 2017 70 "public" 1.2335043992840387 1.1335043992840386 1.3335043992840387 2017 70 "selfem" .402445762522508 .302445762522508 .502445762522508 2017 70 "service" .1849343236595295 .08493432365952949 .28493432365952953 2017 70 "technical" -1.0342492060198605 -1.1342492060198606 -.9342492060198605 2017 70 "yedu" 1.0906702127939947 .9906702127939947 1.1906702127939948 2017 80 "exp" 1.2355772131283367 1.1355772131283366 1.3355772131283368 2017 80 "exp2" -.7889047479434359 -.8889047479434359 -.6889047479434359 2017 80 "invshare" .680144929712355 .580144929712355 .7801449297123549 2017 80 "lnpd" -.6876543138315264 -.7876543138315264 -.5876543138315264 2017 80 "lnseadis" -.28344997391548615 -.3834499739154862 -.18344997391548615 2017 80 "male" .07918646862877618 -.020813531371223826 .17918646862877619 2017 80 "marriage" .9567095536698645 .8567095536698646 1.0567095536698645 2017 80 "public" -.5339290822611201 -.6339290822611201 -.43392908226112015 2017 80 "selfem" -1.459664238591389 -1.559664238591389 -1.3596642385913889 2017 80 "service" -.3041234432769887 -.4041234432769887 -.2041234432769887 2017 80 "technical" -.4791620155276589 -.5791620155276589 -.37916201552765894 2017 80 "yedu" .13618378076096568 .03618378076096568 .2361837807609657 2017 90 "exp" -.06444355757461907 -.1644435575746191 .03555644242538093 2017 90 "exp2" -.4899046792068609 -.589904679206861 -.3899046792068609 2017 90 "invshare" 1.4376663542636432 1.337666354263643 1.5376663542636433 2017 90 "lnpd" -.8007832611629466 -.9007832611629466 -.7007832611629467 2017 90 "lnseadis" .7495925808932434 .6495925808932435 .8495925808932434 2017 90 "male" .21165050395802154 .11165050395802154 .3116505039580215 2017 90 "marriage" .2749107419789901 .17491074197899012 .3749107419789901 2017 90 "public" -.06498988433894477 -.1649898843389448 .03501011566105523 2017 90 "selfem" -1.7271415617216357 -1.8271415617216358 -1.6271415617216356 2017 90 "service" -.1548813266071734 -.25488132660717344 -.0548813266071734 2017 90 "technical" .7382658608899583 .6382658608899583 .8382658608899583 2017 90 "yedu" .7893005837575984 .6893005837575984 .8893005837575984 2017 10 "exp" -1.8890132964697564 -1.9890132964697564 -1.7890132964697563 2005 10 "exp2" -1.2138375042556755 -1.3138375042556756 -1.1138375042556754 2005 10 "invshare" -.7084165727951628 -.8084165727951628 -.6084165727951628 2005 10 "lnpd" -.27580260801127743 -.3758026080112774 -.17580260801127742 2005 10 "lnseadis" .7038005135292276 .6038005135292276 .8038005135292275 2005 10 "male" .3161040877639832 .21610408776398318 .4161040877639832 2005 10 "marriage" -.27828842550384214 -.3782884255038421 -.17828842550384214 2005 10 "public" -.3758992940731389 -.4758992940731389 -.27589929407313885 2005 10 "selfem" -1.0313008262839232 -1.1313008262839233 -.9313008262839232 2005 10 "service" -.23125314985935788 -.3312531498593579 -.13125314985935788 2005 10 "technical" 1.37436465266078 1.27436465266078 1.47436465266078 2005 10 "yedu" 2.0953068266163077 1.9953068266163076 2.195306826616308 2005 20 "exp" .021011085745716262 -.07898891425428374 .12101108574571627 2005 20 "exp2" .3919922525878253 .29199225258782524 .4919922525878253 2005 20 "invshare" .9191590999563001 .8191590999563001 1.0191590999563 2005 20 "lnpd" .23248651982187216 .13248651982187215 .33248651982187216 2005 20 "lnseadis" -.8747825311411459 -.9747825311411459 -.7747825311411459 2005 20 "male" -.524618357845267 -.624618357845267 -.424618357845267 2005 20 "marriage" 1.3766135428341604 1.2766135428341603 1.4766135428341605 2005 20 "public" -1.6790905585590263 -1.7790905585590264 -1.5790905585590262 2005 20 "selfem" 1.3212453162175546 1.2212453162175545 1.4212453162175547 2005 20 "service" -.6270379523590176 -.7270379523590176 -.5270379523590176 2005 20 "technical" -.7538634927913619 -.8538634927913619 -.6538634927913619 2005 20 "yedu" 2.2295590120110673 2.1295590120110672 2.3295590120110674 2005 30 "exp" .1185263167302499 .01852631673024989 .21852631673024991 2005 30 "exp2" 1.2592674623423883 1.1592674623423882 1.3592674623423884 2005 30 "invshare" -1.478835749983807 -1.578835749983807 -1.3788357499838069 2005 30 "lnpd" -.62206091131887 -.72206091131887 -.52206091131887 2005 30 "lnseadis" 1.4115575948587267 1.3115575948587266 1.5115575948587268 2005 30 "male" -2.53358759877479 -2.63358759877479 -2.43358759877479 2005 30 "marriage" .3870656923327805 .28706569233278045 .4870656923327805 2005 30 "public" -.28851945120968414 -.3885194512096841 -.18851945120968414 2005 30 "selfem" -.9287874106075915 -1.0287874106075916 -.8287874106075915 2005 30 "service" -.1596153546379324 -.2596153546379324 -.05961535463793238 2005 30 "technical" -2.897404950987232 -2.997404950987232 -2.797404950987232 2005 30 "yedu" -.6056365224412789 -.7056365224412788 -.5056365224412789 2005 40 "exp" .23089607277461 .13089607277461 .33089607277461 2005 40 "exp2" -.2868930695307711 -.38689306953077107 -.1868930695307711 2005 40 "invshare" -1.2623050041042263 -1.3623050041042264 -1.1623050041042262 2005 40 "lnpd" -1.1717716017406923 -1.2717716017406924 -1.0717716017406922 2005 40 "lnseadis" .18873171128815305 .08873171128815305 .28873171128815306 2005 40 "male" 1.0632136758023543 .9632136758023543 1.1632136758023544 2005 40 "marriage" .5146290526166754 .4146290526166754 .6146290526166753 2005 40 "public" -.32373775060520665 -.4237377506052067 -.22373775060520665 2005 40 "selfem" .10355101002676222 .0035510100267622108 .20355101002676224 2005 40 "service" .3324829330582776 .23248293305827758 .43248293305827756 2005 40 "technical" -.07134033978009104 -.17134033978009106 .02865966021990897 2005 40 "yedu" -.09577237531754226 -.19577237531754227 .004227624682457742 2005 50 "exp" -.32671564766757644 -.4267156476675764 -.22671564766757643 2005 50 "exp2" -.9778696102160698 -1.0778696102160699 -.8778696102160698 2005 50 "invshare" 1.4644264382242749 1.3644264382242748 1.564426438224275 2005 50 "lnpd" .9441876300023767 .8441876300023767 1.0441876300023767 2005 50 "lnseadis" 1.4360728923125161 1.336072892312516 1.5360728923125162 2005 50 "male" .9277529067877425 .8277529067877425 1.0277529067877424 2005 50 "marriage" .33104118260991483 .23104118260991482 .43104118260991486 2005 50 "public" .33265611556291613 .23265611556291613 .43265611556291617 2005 50 "selfem" .9129689049088233 .8129689049088233 1.0129689049088233 2005 50 "service" .5025849123300492 .4025849123300492 .6025849123300492 2005 50 "technical" -1.406230651738646 -1.5062306517386461 -1.306230651738646 2005 50 "yedu" -1.4126941948811649 -1.512694194881165 -1.3126941948811648 2005 60 "exp" -.7016018139303309 -.8016018139303309 -.601601813930331 2005 60 "exp2" -.05807700174125756 -.15807700174125755 .04192299825874245 2005 60 "invshare" .7852508380797718 .6852508380797718 .8852508380797718 2005 60 "lnpd" .9475525047558369 .8475525047558369 1.047552504755837 2005 60 "lnseadis" 2.014875498296482 1.9148754982964817 2.114875498296482 2005 60 "male" -.07212611655964384 -.17212611655964383 .02787388344035617 2005 60 "marriage" -1.892421968411205 -1.992421968411205 -1.7924219684112048 2005 60 "public" 1.5846272252366067 1.4846272252366066 1.6846272252366068 2005 60 "selfem" .7490779754056119 .649077975405612 .8490779754056119 2005 60 "service" -.1164312414968339 -.2164312414968339 -.016431241496833893 2005 60 "technical" .03716339339416066 -.06283660660583934 .13716339339416067 2005 60 "yedu" -.5253382170798304 -.6253382170798304 -.42533821707983044 2005 70 "exp" -2.025942412138202 -2.125942412138202 -1.9259424121382018 2005 70 "exp2" 1.0482071797535162 .9482071797535162 1.1482071797535163 2005 70 "invshare" .892439542285959 .792439542285959 .992439542285959 2005 70 "lnpd" .1429070275274854 .0429070275274854 .24290702752748541 2005 70 "lnseadis" -1.7745921901905606 -1.8745921901905607 -1.6745921901905605 2005 70 "male" -.32565181742246213 -.42565181742246216 -.22565181742246213 2005 70 "marriage" .6739056583283646 .5739056583283646 .7739056583283646 2005 70 "public" -.12805864602638117 -.22805864602638118 -.028058646026381168 2005 70 "selfem" .49386549446324046 .3938654944632405 .5938654944632404 2005 70 "service" -1.7038848117176781 -1.8038848117176782 -1.603884811717678 2005 70 "technical" .3752526191025417 .27525261910254173 .4752526191025417 2005 70 "yedu" -.6851990274761571 -.7851990274761571 -.5851990274761572 2005 80 "exp" -1.8052275966951186 -1.9052275966951187 -1.7052275966951185 2005 80 "exp2" 1.3449605617229008 1.2449605617229007 1.4449605617229009 2005 80 "invshare" -.04047158367738277 -.14047158367738277 .05952841632261723 2005 80 "lnpd" -1.7120469493082826 -1.8120469493082827 -1.6120469493082825 2005 80 "lnseadis" .2530643439341663 .15306434393416632 .3530643439341663 2005 80 "male" -.9791146678759197 -1.0791146678759198 -.8791146678759197 2005 80 "marriage" 1.0423276252242524 .9423276252242524 1.1423276252242525 2005 80 "public" -1.6001662674475192 -1.7001662674475193 -1.5001662674475191 2005 80 "selfem" .38705502006783576 .2870550200678358 .48705502006783574 2005 80 "service" .41040860914150934 .31040860914150936 .5104086091415093 2005 80 "technical" -1.4264655332959688 -1.526465533295969 -1.3264655332959687 2005 80 "yedu" -.7900798737208891 -.890079873720889 -.6900798737208891 2005 90 "exp" -1.899759600423586 -1.999759600423586 -1.7997596004235858 2005 90 "exp2" .12210533124994319 .022105331249943183 .2221053312499432 2005 90 "invshare" .16421962648868288 .06421962648868287 .2642196264886829 2005 90 "lnpd" .14179164523380483 .041791645233804825 .24179164523380484 2005 90 "lnseadis" -.801743833919848 -.901743833919848 -.7017438339198481 2005 90 "male" -.9198942098997105 -1.0198942098997106 -.8198942098997105 2005 90 "marriage" .19116029477242208 .09116029477242207 .2911602947724221 2005 90 "public" -1.3876187915402305 -1.4876187915402306 -1.2876187915402304 2005 90 "selfem" -.4570584177383396 -.5570584177383396 -.3570584177383396 2005 90 "service" -.6558170233711267 -.7558170233711267 -.5558170233711267 2005 90 "technical" 1.5387375190160923 1.4387375190160923 1.6387375190160924 2005 90 "yedu" -1.2077604453191142 -1.3077604453191143 -1.107760445319114 2005 end
0 Response to add legend to one of the graphs in -graph combine-
Post a Comment