Announcement

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

  • a single line plot with 4 different variables? How to code this?

    Good day all

    I am a beginner with Stata, my knowledge is limited to coding for graphs.

    Still, I have a problem. I need to plot line graphs for 2 variables (one data pair), but these have two other variable identifiers (with 3 different values for each, for SI: 1m, 2m, and 3m. for SCR: 90, 60 and 30). The data pairs to be plotted are RQDc and FIc. Hence, I need to produce a single line plot with 9 lines. I tried with bytwoway command with if condition, but got nothing. Help please
    SI SCR RQDc FIc
    1m 90 0 0
    1m 90 0.467165 1.111111
    1m 90 0.844262 2.222222
    1m 90 1.178511 3.333333
    1m 90 1.48609 4.444444
    1m 90 1.774842 5.555556
    1m 90 2.049294 6.666667
    1m 90 2.312347 7.777778
    1m 90 2.566001 8.888889
    1m 90 2.811707 10
    1m 90 3.050558 11.11111
    1m 90 3.283408 12.22222
    1m 90 3.510936 13.33333
    1m 90 3.733695 14.44444
    1m 90 3.952144 15.55556
    1m 90 45 16.66667
    1m 60 60 0
    1m 60 50.45378 1.666667
    1m 60 45.59014 3.333333
    1m 60 42.42641 5
    1m 60 40.12442 6.666667
    1m 60 38.33659 8.333333
    1m 60 36.88729 10
    1m 60 35.67621 11.66667
    1m 60 34.64102 13.33333
    1m 60 33.74048 15
    1m 60 32.94603 16.66667
    1m 60 32.2371 18.33333
    1m 60 31.59842 20
    1m 60 31.01839 21.66667
    1m 60 30.48796 23.33333
    1m 60 30 25
    1m 30 30 0
    1m 30 25.22689 3.333333
    1m 30 22.79507 6.666667
    1m 30 21.2132 10
    1m 30 20.06221 13.33333
    1m 30 19.16829 16.66667
    1m 30 18.44364 20
    1m 30 17.83811 23.33333
    1m 30 17.32051 26.66667
    1m 30 16.87024 30
    1m 30 16.47301 33.33333
    1m 30 16.11855 36.66667
    1m 30 15.79921 40
    1m 30 15.50919 43.33333
    1m 30 15.24398 46.66667
    1m 30 15 50
    2m 90 90 0
    2m 90 50.45378 1.111111
    2m 90 41.03113 2.222222
    2m 90 36.36549 3.333333
    2m 90 33.43702 4.444444
    2m 90 31.3663 5.555556
    etc..........

  • #2
    Does the following help?

    Code:
    twoway (line RQDc FIc if SI == "1m" & SCR ==30) ///
            (line RQDc FIc if SI == "1m" & SCR ==60) ///
            (line RQDc FIc if SI == "1m" & SCR ==90) ///
            (line RQDc FIc if SI == "2m" & SCR ==30) ///
            (line RQDc FIc if SI == "2m" & SCR ==60) ///
            (line RQDc FIc if SI == "2m" & SCR ==90)
    The SI variable value are 1m and 2m. Hence you only get six lines with this code.

    Comment


    • #3
      Originally posted by Tarun Choudhary View Post
      Does the following help?

      Code:
      twoway (line RQDc FIc if SI == "1m" & SCR ==30) ///
      (line RQDc FIc if SI == "1m" & SCR ==60) ///
      (line RQDc FIc if SI == "1m" & SCR ==90) ///
      (line RQDc FIc if SI == "2m" & SCR ==30) ///
      (line RQDc FIc if SI == "2m" & SCR ==60) ///
      (line RQDc FIc if SI == "2m" & SCR ==90)
      The SI variable value are 1m and 2m. Hence you only get six lines with this code.
      Hi

      There is also 3m. I did not copy all the data. My editor does not recognize /// as legit. It reports

      / / / is not a twoway plot type

      Any other way to input 9 line command rows in sequence?

      Comment


      • #4
        /// works fine in a file. Use the do-file editor window or a do-file and Tarun Choudhary's code should work fine. See help comments for the full story.


        Consider also sepscatter from SSC. ttps://www.statalist.org/forums/forum/general-stata-discussion/general/3803-sepscatter-available-from-ssc


        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input str2 SI byte SCR float(RQDC FIc)
        "1m" 90        0        0
        "1m" 90  .467165 1.111111
        "1m" 90  .844262 2.222222
        "1m" 90 1.178511 3.333333
        "1m" 90  1.48609 4.444444
        "1m" 90 1.774842 5.555556
        "1m" 90 2.049294 6.666667
        "1m" 90 2.312347 7.777778
        "1m" 90 2.566001 8.888889
        "1m" 90 2.811707       10
        "1m" 90 3.050558 11.11111
        "1m" 90 3.283408 12.22222
        "1m" 90 3.510936 13.33333
        "1m" 90 3.733695 14.44444
        "1m" 90 3.952144 15.55556
        "1m" 90       45 16.66667
        "1m" 60       60        0
        "1m" 60 50.45378 1.666667
        "1m" 60 45.59014 3.333333
        "1m" 60 42.42641        5
        "1m" 60 40.12442 6.666667
        "1m" 60 38.33659 8.333333
        "1m" 60 36.88729       10
        "1m" 60 35.67621 11.66667
        "1m" 60 34.64102 13.33333
        "1m" 60 33.74048       15
        "1m" 60 32.94603 16.66667
        "1m" 60  32.2371 18.33333
        "1m" 60 31.59842       20
        "1m" 60 31.01839 21.66667
        "1m" 60 30.48796 23.33333
        "1m" 60       30       25
        "1m" 30       30        0
        "1m" 30 25.22689 3.333333
        "1m" 30 22.79507 6.666667
        "1m" 30  21.2132       10
        "1m" 30 20.06221 13.33333
        "1m" 30 19.16829 16.66667
        "1m" 30 18.44364       20
        "1m" 30 17.83811 23.33333
        "1m" 30 17.32051 26.66667
        "1m" 30 16.87024       30
        "1m" 30 16.47301 33.33333
        "1m" 30 16.11855 36.66667
        "1m" 30 15.79921       40
        "1m" 30 15.50919 43.33333
        "1m" 30 15.24398 46.66667
        "1m" 30       15       50
        "2m" 90       90        0
        "2m" 90 50.45378 1.111111
        "2m" 90 41.03113 2.222222
        "2m" 90 36.36549 3.333333
        "2m" 90 33.43702 4.444444
        "2m" 90  31.3663 5.555556
        end
        
        
        egen which = group(SI SCR), label
        
        set scheme s1color 
        sepscatter RQDC FIc, separate(which) recast(connected) legend(ring(0) pos(1) col(1)) yla(, ang(h))
        Code:
        
        


        Click image for larger version

Name:	sepscatter.png
Views:	1
Size:	46.7 KB
ID:	1596522


        recast(line) rather than recast(connected) would work too. For 9 lines, nothing in the command stops a mess if your data lean that way.

        Comment


        • #5
          dear Nick

          I installed SSC via ssc install dataex. But I still get command sepscatter is unrecognized

          Comment


          • #6
            Originally posted by Tarun Choudhary View Post
            Does the following help?

            Code:
            twoway (line RQDc FIc if SI == "1m" & SCR ==30) ///
            (line RQDc FIc if SI == "1m" & SCR ==60) ///
            (line RQDc FIc if SI == "1m" & SCR ==90) ///
            (line RQDc FIc if SI == "2m" & SCR ==30) ///
            (line RQDc FIc if SI == "2m" & SCR ==60) ///
            (line RQDc FIc if SI == "2m" & SCR ==90)
            The SI variable value are 1m and 2m. Hence you only get six lines with this code.
            dear Tarun

            You code worked. Can I please ask for one more shove from you?

            twoway (line FIc RQDC if SI == "1m" & SCR ==30) ///
            (line FIc RQDC if SI == "1m" & SCR ==60) ///
            (line FIc RQDC if SI == "1m" & SCR ==90) ///
            (line FIc RQDC if SI == "2m" & SCR ==30) ///
            (line FIc RQDC if SI == "2m" & SCR ==60) ///
            (line FIc RQDC if SI == "2m" & SCR ==90) ///
            (line FIc RQDC if SI == "3m" & SCR ==30) ///
            (line FIc RQDC if SI == "3m" & SCR ==60) ///
            (line FIc RQDC if SI == "3m" & SCR ==90)

            Now I need to append to each plotted line a legend entry which states two conditional variable values for it, and assign different colors and line types for each.

            Comment


            • #7
              Sorry; you had guess that

              https://www.statalist.org/forums/for...lable-from-ssc

              minus the first h meant the link above -- which explains that you must install sepscatter before you can use it. (Installing dataex just does what it says; it doesn't install anything else.)

              Comment

              Working...
              X