Announcement

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

  • Graph with conditioning

    Hi there, I would like to create a graph with two lines one for each condition. This is what I tried:

    graph twoway (line mean_BARTAdj weekday_ordered if origin_condition==0, line mean_BARTAdj weekday_ordered if origin_condition==1)

  • #2
    Commas introduce options and have other uses and meanings, but they don't ever separate commands.

    Code:
    line mean_BARTAdj weekday_ordered if origin_condition==0 || line mean_BARTAdj weekday_ordered if origin_condition==1

    Comment


    • #3
      Unfortunately, I still only get one line. Maybe for more context

      gen sensecond = sense > 2
      lab def condition 0 "low" 1 "high"
      lab values sensecond condition
      egen origin_condition = group(sensecond), label
      collapse (mean) mean_BARTAdj=BARTAdj (sd) sd_BARTAdj=BARTAdj (count) n=BARTAdj, by(origin_condition weekday)

      * generate a numerical variable with labels of the string variable
      * you cannot use string variables for a line plot
      label define order 1 M 2 Tu 3 W 4 Th 5 F 6 Sa 7 Su
      encode weekday, generate(weekday_ordered) label (order)
      sort weekday_ordered

      line mean_BARTAdj weekday_ordered if origin_condition==0 || line mean_BARTAdj weekday_ordered if origin_condition==1

      Comment


      • #4
        Your code looks good to me. So I suspect that some assumption about your data is wrong. Please show the results of

        Code:
        dataex mean_BARTAdj weekday_ordered origin_condition

        Comment


        • #5
          . dataex mean_BARTAdj weekday_ordered origin_condition

          ----------------------- copy starting from the next line -----------------------
          Code:
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input double mean_BARTAdj long weekday_ordered float origin_condition
          31.978152856584227 1 1
           34.80145448687116 1 2
           33.82251130314856 2 2
          32.545402364520015 2 1
           36.27314413074217 3 2
          31.548568465847875 3 1
           31.18929699113523 4 1
          33.821495287120285 4 2
          33.971447919364586 5 2
          32.447326516076515 5 1
          34.302633681677804 6 2
          31.286982693232694 6 1
           37.93971907721908 7 2
           31.58368080721022 7 1
          end
          label values weekday_ordered order
          label def order 1 "M", modify
          label def order 2 "Tu", modify
          label def order 3 "W", modify
          label def order 4 "Th", modify
          label def order 5 "F", modify
          label def order 6 "Sa", modify
          label def order 7 "Su", modify
          label values origin_condition origin_condition
          label def origin_condition 1 "low", modify
          label def origin_condition 2 "high", modify
          ------------------ copy up to and including the previous line ------------------

          Listed 14 out of 14 observations

          .

          Comment


          • #6
            The values of origin_condition are 1 and 2. You asked to see results for 0 (there aren't any) and 1.

            Comment


            • #7
              Here is some technique to fool around with.

              Code:
              decode origin, gen(toshow)
              set scheme s1color 
              line mean weekday if origin == 1, lc(red) || line mean weekday if origin == 2 , lc(blue) ///
              xla(1/7, valuelabel) xtitle("") yla(, ang(h)) xsc(r(. 7.5)) legend(off) ///
              ytitle(something less barbarous belongs here) /// 
              || scatter mean weekday if origin == 1 & week == 7, ms(none) mla(toshow) mlabc(red) mlabsize(medium) /// 
              || scatter mean weekday if origin == 2 & week == 7, ms(none) mla(toshow) mlabc(blue) mlabsize(medium)
              Click image for larger version

Name:	opitz.png
Views:	1
Size:	41.0 KB
ID:	1595475

              Comment


              • #8
                Hi, thank you very much, that worked. Now I would also like to include se and created variables accordingly, but the code for the graph is not working:

                generate hiBARTAdj = mean_BARTAdj + (sd_BARTAdj / sqrt(n))
                generate lowBARTAdj = mean_BARTAdj - (sd_BARTAdj / sqrt(n))
                line mean_BARTAdj weekday_ordered (rcap hiBARTAdj lowBARTAdj weekday_ordered) if origin_condition==1 || line mean_BARTAdj weekday_ordered (rcap hiBARTAdj lowBARTAdj weekday_ordered) if origin_condition==2, legend(label(1 "high sense") label(2 "low sense")) title("BART by weekday sense")

                Comment


                • #9
                  "not working" could mean anything here from "I got an error message" to "I didn't get the graph I wanted".

                  You're mixing quite different syntaxes. That may be legal but I would keep to one syntax. When commands get that complicated, I open up the Do-file editor and do something like


                  Code:
                  line mean_BARTAdj weekday_ordered if origin_condition == 1 ///
                  || rcap hiBARTAdj lowBARTAdj weekday_ordered if origin_condition==1 ///
                  || line mean_BARTAdj weekday_ordered if origin_condition == 2 ///
                  || rcap hiBARTAdj lowBARTAdj weekday_ordered if origin_condition==2, ///
                  legend(label(1 "high sense") label(2 "low sense")) title("BART by weekday sense")

                  Comment


                  • #10
                    Thank you. One last extension: How can I adjust the yscale? I would like to have scores from 25 to 40

                    Comment


                    • #11
                      Code:
                      help axis scale options
                      Last edited by Nick Cox; 05 Mar 2021, 11:28.

                      Comment

                      Working...
                      X