Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Graph

    Dear prof and colleagues,

    I am going to plot this graph with three variables:
    1- year (2010-2020)
    2-shr_immg
    3-expgr

    I used these codes, but it keeps saying "parentheses do not balance". Could you please assist me to find what I am missing?? Thanks.

    Code:
    twoway (line shr_immg expgr if year==2010 & sk_rat==1, lcolor(gs10)) ///
    (line shr_immg expgr if year==2011 & sk_rat==1, lcolor(black) lpat(dash_3dot)) ///
    (line shr_immg expgr if year==2012 & sk_rat==1, lcolor(gs7) lpat(vshortdash)) /// 
    (line shr_immg expgr if year==2013 & sk_rat==1, lcolor(black) lpat(dot)) ///
    (line shr_immg expgr if year==2014 & sk_rat==1, lcolor(black) lpat(dash)) ///
    (line shr_immg expgr if year==2015 & sk_rat==1, lcolor(black) lpat(solid)) ///
    (line shr_immg expgr if year==2016 & sk_rat==1, lcolor(black) lpat(vshortdash)) ///
    (line shr_immg expgr if year==2017 & sk_rat==1, lcolor(gs10) lpat(dash)) ///
    (line shr_immg expgr if year==2018 & sk_rat==1, lcolor(black) lpat(dash)) ///
    (line shr_immg expgr if year==2019 & sk_rat==1, lcolor(black) lpat(solid)) ///
    (line shr_immg expgr if year==2020 & sk_rat==1, lcolor(black) lpat(vshortdash)),legend(label(1 "2010") ///
    label(2 "2011") label(3 "2012") label(4 "2013") label(5 "2014") label(6 "2015") label(7 "2016")label(8 "2017")label(9 "2018")label(10 "2019")abel(11 "2020")cols(11)) ylab(,nogrid) ///
    ti("Panel A: 1st Quartile", size(medium) color(black)) xti("Years of Experience", size(medium)) ///
    yti("Immigrant Share") graphr(ic(white) ifc(white) ilc(white) fcolor(white) lcolor(white)) ///


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double year float(shr_immg expgr)
    2010  .06171435  2.5
    2011  .05453846  2.5
    2012   .0449036  2.5
    2013  .04390729  2.5
    2014  .03895496  2.5
    2015  .03910635  2.5
    2016  .04279581  2.5
    2017  .04302535  2.5
    2018    .063071  2.5
    2019   .0894574  2.5
    2020  .10602682  2.5
    2010  .08200432  2.5
    2011   .0773884  2.5
    2012  .07025904  2.5
    2013  .06849734  2.5
    2014  .06925854  2.5
    2015  .07755903  2.5
    2016  .07361327  2.5
    2017   .0811235  2.5
    2018  .09596717  2.5
    2019   .1220758  2.5
    2020  .11485728  2.5
    2010  .06260721  2.5
    2011  .06052116  2.5
    2012  .05774609  2.5
    2013  .05200341  2.5
    2014  .04920107  2.5
    2015  .04890267  2.5
    2016   .0518006  2.5
    2017  .05483922  2.5
    2018    .069535  2.5
    2019  .09092128  2.5
    2020  .08955224  2.5
    2010   .0205613  2.5
    2011  .02385999  2.5
    2012  .02410142  2.5
    2013  .02806499  2.5
    2014 .033377003  2.5
    2015  .03494056  2.5
    2016  .05138873  2.5
    2017  .05860748  2.5
    2018 .067040175  2.5
    2019  .07334909  2.5
    2020  .07404434  2.5
    2010  .06755392  7.5
    2011  .06247599  7.5
    2012  .05508118  7.5
    2013  .05292348  7.5
    2014  .05155229  7.5
    2015  .05364485  7.5
    2016  .06471722  7.5
    2017  .07110058  7.5
    2018  .08763703  7.5
    2019  .12339999  7.5
    2020   .1540426  7.5
    2010  .08372635  7.5
    2011  .08705437  7.5
    2012  .07872606  7.5
    2013   .0759871  7.5
    2014  .08105429  7.5
    2015  .08917474  7.5
    2016  .09663171  7.5
    2017  .10516166  7.5
    2018  .12653647  7.5
    2019  .16030076  7.5
    2020  .16280566  7.5
    2010   .0598473  7.5
    2011  .06322471  7.5
    2012  .05262017  7.5
    2013  .05562126  7.5
    2014  .05653569  7.5
    2015  .06050209  7.5
    2016  .06544687  7.5
    2017  .07047031  7.5
    2018  .08401076  7.5
    2019    .108907  7.5
    2020  .10477254  7.5
    2010 .021303535  7.5
    2011  .02407722  7.5
    2012  .02414379  7.5
    2013  .02639147  7.5
    2014  .03146543  7.5
    2015  .03624856  7.5
    2016  .04605805  7.5
    2017  .05516027  7.5
    2018 .066012345  7.5
    2019   .0809857  7.5
    2020  .09259596  7.5
    2010   .0877129 12.5
    2011  .07381125 12.5
    2012  .05937796 12.5
    2013  .05513486 12.5
    2014  .05231099 12.5
    2015  .05432476 12.5
    2016  .06026341 12.5
    2017  .06709786 12.5
    2018  .08755108 12.5
    2019  .12383803 12.5
    2020  .15144126 12.5
    2010  .08574042 12.5
    end

    Cheers,
    Paris

  • #2
    You have problems on several levels here.

    A. Finding your missing or superfluous parenthesis. I didn't find it but
    Code:
     abel(11 "2020") 
    is a typo and you may need more spaces in the legend() option. I dislike the () syntax for separating twoway calls, for precisely this reason: there are already lots of parentheses to keep track of. I recommend the || syntax.

    B. The code refers to sk_rat but there is no such variable in the data example. Thus our scope for experimentation is limited.

    C. The structure appears to be values for

    3 or more levels of one predictor expgr

    4(?) or levels of another predictor sk_rat

    11 years of data.

    and one outcome. You're trying to draw perhaps 44 lines. Already for a subset of your data you have 11 lines and 11 legend items.

    I'd venture the assertion that once a legend has more than about 5 items, the game is lost. No one, not even the designer, has the ability to disentangle the signal from the noise in a reasonably short time when the obligation is back and forth between legend and plot region to find out which is which: that can be done individually at best. Also, the space taken up by the legend will squeeze the data region.

    Am I being too pessimistic? I am a big believer in looking at data, but sometimes you need to fit a model first!
    Last edited by Nick Cox; 24 Mar 2023, 10:17.

    Comment


    • #3
      Dear Nick, Thank you for getting back to me.

      I am going to plot something like this :
      Click image for larger version

Name:	fig.1.png
Views:	1
Size:	33.6 KB
ID:	1707015

      Comment


      • #4
        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input double year byte sk_rat float(shr_immg expgr)
        2010 1  .06171435  2.5
        2011 1  .05453846  2.5
        2012 1   .0449036  2.5
        2013 1  .04390729  2.5
        2014 1  .03895496  2.5
        2015 1  .03910635  2.5
        2016 1  .04279581  2.5
        2017 1  .04302535  2.5
        2018 1    .063071  2.5
        2019 1   .0894574  2.5
        2020 1  .10602682  2.5
        2010 1  .06755392  7.5
        2011 1  .06247599  7.5
        2012 1  .05508118  7.5
        2013 1  .05292348  7.5
        2014 1  .05155229  7.5
        2015 1  .05364485  7.5
        2016 1  .06471722  7.5
        2017 1  .07110058  7.5
        2018 1  .08763703  7.5
        2019 1  .12339999  7.5
        2020 1   .1540426  7.5
        2010 1   .0877129 12.5
        2011 1  .07381125 12.5
        2012 1  .05937796 12.5
        2013 1  .05513486 12.5
        2014 1  .05231099 12.5
        2015 1  .05432476 12.5
        2016 1  .06026341 12.5
        2017 1  .06709786 12.5
        2018 1  .08755108 12.5
        2019 1  .12383803 12.5
        2020 1  .15144126 12.5
        2010 1  .08768456 17.5
        2011 1   .0780023 17.5
        2012 1  .06422645 17.5
        2013 1  .06091054 17.5
        2014 1  .05959893 17.5
        2015 1  .05941565 17.5
        2016 1  .05930433 17.5
        2017 1   .0619821 17.5
        2018 1  .07540318 17.5
        2019 1  .10154062 17.5
        2020 1  .12189952 17.5
        2010 1  .07737408 22.5
        2011 1  .06982936 22.5
        2012 1  .06072408 22.5
        2013 1  .05711767 22.5
        2014 1  .05601443 22.5
        2015 1  .05577151 22.5
        2016 1   .0565187 22.5
        2017 1  .06124174 22.5
        2018 1 .067610644 22.5
        2019 1   .0835649 22.5
        2020 1    .097122 22.5
        2010 1  .06460338 27.5
        2011 1  .05705247 27.5
        2012 1  .04812486 27.5
        2013 1  .04712152 27.5
        2014 1  .04977541 27.5
        2015 1   .0500335 27.5
        2016 1  .05049135 27.5
        2017 1  .05140962 27.5
        2018 1    .056031 27.5
        2019 1  .06463504 27.5
        2020 1  .07048229 27.5
        2010 1   .0585946 32.5
        2011 1  .05221253 32.5
        2012 1  .04333231 32.5
        2013 1  .03987047 32.5
        2014 1  .03974682 32.5
        2015 1  .04016667 32.5
        2016 1  .04076798 32.5
        2017 1  .03992411 32.5
        2018 1  .04439316 32.5
        2019 1  .04887223 32.5
        2020 1   .0537794 32.5
        2010 1  .04302633 37.5
        2011 1  .03979434 37.5
        2012 1   .0342999 37.5
        2013 1 .033641733 37.5
        2014 1 .035869837 37.5
        2015 1 .036004398 37.5
        2016 1 .036658265 37.5
        2017 1 .034949135 37.5
        2018 1 .036431696 37.5
        2019 1  .03838323 37.5
        2020 1  .03813249 37.5
        2010 2  .08200432  2.5
        2011 2   .0773884  2.5
        2012 2  .07025904  2.5
        2013 2  .06849734  2.5
        2014 2  .06925854  2.5
        2015 2  .07755903  2.5
        2016 2  .07361327  2.5
        2017 2   .0811235  2.5
        2018 2  .09596717  2.5
        2019 2   .1220758  2.5
        2020 2  .11485728  2.5
        2010 2  .08372635  7.5
        end
        
         tab sk_rat
        
        4 quantiles |
        of sk_ratio |      Freq.     Percent        Cum.
        ------------+-----------------------------------
                  1 |         88       25.00       25.00
                  2 |         88       25.00       50.00
                  3 |         88       25.00       75.00
                  4 |         88       25.00      100.00
        ------------+-----------------------------------
              Total |        352      100.00
        
        . tab expgr
        
              expgr |      Freq.     Percent        Cum.
        ------------+-----------------------------------
                2.5 |         44       12.50       12.50
                7.5 |         44       12.50       25.00
               12.5 |         44       12.50       37.50
               17.5 |         44       12.50       50.00
               22.5 |         44       12.50       62.50
               27.5 |         44       12.50       75.00
               32.5 |         44       12.50       87.50
               37.5 |         44       12.50      100.00
        ------------+-----------------------------------
              Total |        352      100.00
        Enable GingerCannot connect to Ginger Check your internet connection
        or reload the browserDisable in this text fieldRephraseRephrase current sentence5Edit in GingerĂ—
        Last edited by Paris Rira; 24 Mar 2023, 10:30.

        Comment


        • #5
          Thanks for the revised data example, and other results, which makes clear that your structure is indeed

          11 years X 8 values of expgr X 4 levels of sk_rat and one outcome.

          -- so, as said, 44 lines wanted. Ignoring the values for sk_rat == 2 I get this:

          Code:
          . sort year expgr 
          
          . levelsof expgr, local(levels)
          2.5 7.5 12.5 17.5 22.5 27.5 32.5 37.5
          
          . line shr_immg expgr, c(L) xla(`levels')

          Click image for larger version

Name:	paris1.png
Views:	1
Size:	47.5 KB
ID:	1707021

          -- which doesn't begin to answer the questions of how a legend would make that easier to understand, or how to add in the other 3/4 of your dataset.


          A front-and-back plot might help with the first problem, but not I imagine the second. https://www.statalist.org/forums/for...ailable-on-ssc is the most relevant thread, but fabplot isn't mentioned until late.


          Code:
          fabplot line shr expgr if sk_rat == 1, by(year) frontopts(lw(thick))
          Click image for larger version

Name:	paris2.png
Views:	1
Size:	81.4 KB
ID:	1707022

          Comment


          • #6
            Thank you Nick.

            But the point is that I am going to plot each sk_rat separately. So I cannot ignore it.
            You plot all values of sk_rat together. But I need 4 outcomes not one.

            Comment


            • #7
              What I need is :
              Click image for larger version

Name:	plot.png
Views:	1
Size:	142.7 KB
ID:	1707204


              Beacuse I am going to analyze each line of each panel separately. That is why each must be each distinguishable line form the other to see how are their trends.
              In this example there are 6 years, so 6 lines in each panel.
              In my case there are 11 years, therefore 11 lines in each panel should show up.

              Comment


              • #8
                You can get something like by using separate to get a separate variable for each year. Something

                Code:
                separate shr_immg, by(year) veryshortlabel 
                
                line shr_immg???? expgr, by(sk_rat) ,

                Comment


                • #9
                  I am afraid I can't get your point, Nick.

                  Comment


                  • #10
                    I've given you code to try. That is my only new point.

                    Comment

                    Working...
                    X