Announcement

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

  • Graph, multilevel

    Error term after running Graph twoway connected:

    ) required
    r(100);

    Question: where is/are the bracket(s) missing?

    mixed satis rural##oneperson rural##localperson rural##ib5.classp ginicent lngnicent colony communism ||region:, covariance(unstructured)mle variance nostder

    graph twoway connected predsatisr rural if region==1, xlabel(0 1, valuelabel) lpattern(dot) || ///
    > title("Prediction of life satisfaction") ytitle("Life satisfaction, predicted") legend (col(1) lab(1"Sinic") lab(2"SEAsia") lab(3"Arabic") lab(4"Africa") lab(5"Europe") lab(6
    > "PCE") lab(7"LA") lab(8"ANSaxon")) (subtitle("Legend")) scheme(s1mono) ///
    > connected predsatisr rural if region==2, xlabel(0 1, valuelabel) lpattern(dash) || ///
    > connected predsatisr rural if region==3, xlabel(0 1, valuelabel) lpattern(1) || ///
    > connected predsatisr rural if region==4, xlabel(0 1, valuelabel) lpattern(shortdash_dot) || ///
    > connected predsatisr rural if region==5, xlabel(0 1, valuelabel) lpattern(shortdash) || ///
    > connected predsatisr rural if region==6, xlabel(0 1, valuelabel) lpattern("__...") || ///
    > connected predsatisr rural if region==7, xlabel(0 1, valuelabel) lpattern(longdash_dot) || ///
    > connected predsatisr rural if region==8, xlabel(0 1, valuelabel) lpattern(dash_dot)
    ) required
    r(100);

    Used: STATA MP 17, on Windows, Microsoft 365 (office)

  • #2
    Originally posted by Ingrid Grosse View Post
    Question: where is/are the bracket(s) missing?
    I'm guessing that you're not allowed to surround the subtitle() with parentheses, and am surprised that your code executed at all the way the options are separated by a double-pipe (plot separator) from the first plot's command and precede the second plot's command.

    Try something like the following, which runs.
    Code:
    version 17.0
    
    clear *
    
    // seedem
    set seed 601367076
    
    quietly set obs 8
    generate byte region = _n
    
    quietly expand 2
    bysort region: generate byte rural = _n - 1
    label define NY 0 N 1 Y
    label values rural NY
    
    generate double predsatisr = runiform()
    
    *
    * Begin here
    *
    graph twoway ///
        connected predsatisr rural if region==1, xlabel(0 1, valuelabel) lpattern(dot) || ///
        connected predsatisr rural if region==2, xlabel(0 1, valuelabel) lpattern(dash) || ///
        connected predsatisr rural if region==3, xlabel(0 1, valuelabel) lpattern(1) || ///
        connected predsatisr rural if region==4, xlabel(0 1, valuelabel) lpattern(shortdash_dot) || ///
        connected predsatisr rural if region==5, xlabel(0 1, valuelabel) lpattern(shortdash) || ///
        connected predsatisr rural if region==6, xlabel(0 1, valuelabel) lpattern("__...") || ///
        connected predsatisr rural if region==7, xlabel(0 1, valuelabel) lpattern(longdash_dot) || ///
        connected predsatisr rural if region==8, xlabel(0 1, valuelabel) lpattern(dash_dot) ///
            title("Prediction of life satisfaction") ytitle("Life satisfaction, predicted") ///
            legend(col(1) label(1 "Sinic") label(2 "SEAsia") label(3 "Arabic") label(4 "Africa") ///
                label(5 "Europe") lab(6 "PCE") lab(7 "LA") lab(8 "ANSaxon")) ///
            subtitle("Legend") scheme(s1mono)
    
    exit
    I suggest a cleaner, leaner look to the graph.

    Comment


    • #3
      My guess is a bit different as I think the first || is quite wrong and is confusing the parser.

      The bigger deal is that this is likely to be a confusing mess. Also, you're sacrificing perhaps 1/3 or 1/4 of your space to a legend.

      https://www.statalist.org/forums/for...ailable-on-ssc -- a long thread, but skim and skip until fabplot is mentioned -- suggests some alternatives to spaghetti, as do

      Code:
      . search spaghetti, sj
      
      Search of official help files, FAQs, Examples, and Stata Journals
      
      SJ-21-2 gr0087  . . Front-and-back plots to ease spaghetti and paella problems
              (help fabplot if installed) . . . . . . . . . . . . . . . .  N. J. Cox
              Q2/21   SJ 21(2):539--554
              explores front-and-back plots, in which each subset of data
              is shown separately with the other subsets as backdrop
      
      SJ-19-4 gr0080  . . . . . .  Some simple devices to ease the spaghetti problem
              . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
              Q4/19   SJ 19(4):989--1008                               (no commands)
              gives guidance on avoiding the spaghetti problem in graphics
              (where multiple time series or other functional traces show
              mostly a tangled mess)
      
      (end of search)

      Comment


      • #4
        Thanks to both of you! Will keep on trying and learning!

        Comment

        Working...
        X