Announcement

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

  • Parentheses do not balance - two line plot

    Hi all, I have data-set as follow:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int year long(education race) float wealth
    1989 1 1  82099.71
    1989 1 2 116755.92
    1989 1 3  512775.7
    1989 1 4   1439511
    1989 2 1  12370.65
    1989 2 2  7370.145
    1989 2 3   63681.8
    1989 2 4 134808.39
    1989 3 1  62730.21
    1989 3 2  40041.36
    1989 3 3   53428.9
    1989 3 4  247786.2
    1992 1 1  169006.6
    1992 1 2 149250.72
    1992 1 3  746245.2
    1992 1 4 1160070.3
    1992 2 1   8603.36
    1992 2 2  5987.135
    1992 2 3  57909.18
    1992 2 4 104036.95
    1992 3 1  58881.89
    1992 3 2  42765.25
    1992 3 3 135582.61
    1992 3 4 189575.83
    1995 1 1 186072.64
    1995 1 2 110403.31
    1995 1 3  985408.3
    1995 1 4 1111941.5
    1995 2 1  10805.43
    1995 2 2   7313.24
    1995 2 3 37497.973
    1995 2 4 122148.34
    1995 3 1  29566.17
    1995 3 2  26465.47
    1995 3 3 130056.66
    1995 3 4 184303.05
    1998 1 1  194332.5
    1998 1 2 173440.03
    1998 1 3  681440.1
    1998 1 4 1458637.4
    1998 2 1  11479.06
    1998 2 2  7104.325
    1998 2 3  18339.94
    1998 2 4 118066.12
    1998 3 1  42493.18
    1998 3 2  31043.63
    1998 3 3  161267.5
    1998 3 4  195940.8
    2001 1 1 171388.64
    2001 1 2 132165.72
    2001 1 3  694361.2
    2001 1 4 2187000.5
    2001 2 1  10906.55
    2001 2 2   7749.75
    2001 2 3  10567.83
    2001 2 4 110420.36
    2001 3 1  23438.92
    2001 3 2  23608.28
    2001 3 3  11638.17
    2001 3 4  218503.6
    2004 1 1 399059.75
    2004 1 2  92820.99
    2004 1 3  685744.9
    2004 1 4 2168642.5
    2004 2 1 14739.955
    2004 2 2  8075.815
    2004 2 3 35927.844
    2004 2 4 116972.14
    2004 3 1  40442.67
    2004 3 2 18599.809
    2004 3 3  72955.78
    2004 3 4  186953.2
    2007 1 1  327370.8
    2007 1 2 147056.33
    2007 1 3  547335.8
    2007 1 4   2686271
    2007 2 1 18678.777
    2007 2 2   6484.88
    2007 2 3  85745.22
    2007 2 4 141277.83
    2007 3 1  49470.41
    2007 3 2  17022.82
    2007 3 3 263680.03
    2007 3 4 256998.27
    2010 1 1   98484.8
    2010 1 2  81783.27
    2010 1 3  384654.4
    2010 1 4   1148666
    2010 2 1   11501.5
    2010 2 2  7350.435
    2010 2 3  40068.16
    2010 2 4  75051.82
    2010 3 1 13413.165
    2010 3 2   8289.97
    2010 3 3  30893.94
    2010 3 4 126952.53
    2013 1 1  99450.03
    2013 1 2  45162.39
    2013 1 3 616291.25
    2013 1 4 1148856.8
    end
    label values education new_education
    label def new_education 1 "college degree", modify
    label def new_education 2 "no college", modify
    label def new_education 3 "some college", modify
    label values race new_race
    label def new_race 1 "Hispanic", modify
    label def new_race 2 "black", modify
    label def new_race 3 "other", modify
    label def new_race 4 "white", modify
    I want to plot graph like this image:

    Click image for larger version

Name:	1.PNG
Views:	1
Size:	60.7 KB
ID:	1662048


    So i have typed code as follow, but something wrong in my code because stata said that: "parentheses do not balance":
    Code:
    sort year
    twoway line wealth year if race==1 & education==1, lcolor(green) lwidth(medthick || ///
        line wealth year if race==1 & education==2, lcolor(green)  lpattern(dash) lwidth(medthick) || ///
        line wealth year if race==1 & education==3, lcolor(green)  lpattern(dot) lwidth(medthick) || ///
        line wealth year if race==2 & education==1, lcolor(red) lwidth(medthick) || ///
        line wealth year if race==2 & education==2, lcolor(red)  lpattern(dash) lwidth(medthick) || ///
        line wealth year if race==2 & education==3, lcolor(red)  lpattern(dot) lwidth(medthick) || ///
        line wealth year if race==3 & education==1,lcolor(sand) lwidth(medthick) || ///
        line wealth year if race==3 & education==2,lcolor(sand) lpattern(dash) lwidth(medthick) || ///
        line wealth year if race==3 & education==3, lcolor(sand)  lpattern(dot) lwidth(medthick) || ///
        line wealth year if race==4 & education==1,lcolar(navy) lwidth(medthick) || ///
        line wealth year if race==4 & education==2,lcolar(navy)  lpattern(dash) lwidth(medthick) || ///
        line wealth year if race==4 & education==3,lcolar(navy)  lpattern(dot) lwidth(medthick) || ///
        xlabel(1989 1995 2004 2010 2016) ytitle(Wealth) xtitle(Year) || ///
        legend(order(1 "College_Hispanic" 2 "College_Black" 3 "College_Other" 4 "College_White" 5 "No_college_Hispanic" 6 "No_college_Black" 7 "No_college_Other" 8 "No_college_White" 9 "Some_college_Hispanic" 10 "Some_college_Black" 11 "Some_college_Other" 12 "Some_college_White" ))
    I would appreciate any suggestions how can plot this graph. Thank you all.

  • #2
    Well your parenthesis do not balance, you have a few typos, and the options need a comma before them. This should work:

    Code:
    twoway line wealth year if race==1 & education==1, lcolor(green) lwidth(medthick) || ///
        line wealth year if race==1 & education==2, lcolor(green)  lpattern(dash) lwidth(medthick) || ///
        line wealth year if race==1 & education==3, lcolor(green)  lpattern(dot) lwidth(medthick) || ///
        line wealth year if race==2 & education==1, lcolor(red) lwidth(medthick) || ///
        line wealth year if race==2 & education==2, lcolor(red)  lpattern(dash) lwidth(medthick) || ///
        line wealth year if race==2 & education==3, lcolor(red)  lpattern(dot) lwidth(medthick) || ///
        line wealth year if race==3 & education==1,lcolor(sand) lwidth(medthick) || ///
        line wealth year if race==3 & education==2,lcolor(sand) lpattern(dash) lwidth(medthick) || ///
        line wealth year if race==3 & education==3, lcolor(sand)  lpattern(dot) lwidth(medthick) || ///
        line wealth year if race==4 & education==1,lcolor(navy) lwidth(medthick) || ///
        line wealth year if race==4 & education==2,lcolor(navy)  lpattern(dash) lwidth(medthick) || ///
        line wealth year if race==4 & education==3,lcolor(navy)  lpattern(dot) lwidth(medthick) , ///
        xlabel(1989 1995 2004 2010 2016) ytitle(Wealth) xtitle(Year)  ///
        legend(order(1 "College_Hispanic" 2 "College_Black" 3 "College_Other" 4 "College_White" 5 "No_college_Hispanic" 6 "No_college_Black" 7 "No_college_Other" 8 "No_college_White" 9 "Some_college_Hispanic" 10 "Some_college_Black" 11 "Some_college_Other" 12 "Some_college_White" ))

    Comment


    • #3
      Your code work. Thank you a lot for helping me.alejoforero.

      Comment

      Working...
      X