Announcement

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

  • two lowess curves within the same graph region

    I run the command below to a lowess curve for two of the indenpendent variables on the same graph, however, Stata only generates two separate graphs for me. I use Stata SE/17.
    logit voted ldmission ldcatho i.gender age age2 education i.urbrur living_cond i.catholic_now i.protestant_now i.muslim_now religiosity lslave_region slave_region ldcity1800 lpopd_history ldcoast ldrail ldexplorer dexplorer_0 ldprint ldhospital ldbig30 i.Country i.Wave
    predict voted_pred_mission, p

    global y_all "voted_pred_mission"

    foreach y of varlist voted_pred_mission{
    cap noisily drop lowess*
    local x: variable label `y'
    lowess `y' ldcatho if ldcatho<5.2, nograph gen(lowess_`y') bwidth(0.5) adjust
    gr twoway line lowess_`y' ldcatho if ldcatho<5.2 ///
    , sort(ldcatho) color(blue) ///

    cap noisily drop lowess*
    local x: variable label `y'
    lowess `y' ldmission if ldmission<5.2, nograph gen(lowess_`y') bwidth(0.5) adjust
    gr twoway line lowess_`y' ldmission if ldmission<5.2 ///
    , sort(ldmission) color(blue) ///
    xtitle("Distance to Mission") ytitle("Probability of Voting") ///
    graphregion(color(white))
    gr export "bymissionvote.pdf", replace
    }


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte gender float(age age2 education) byte(urbrur living_cond) float(catholic_now protestant_now muslim_now) long(Country Wave)
    1 38 1444 2 2 3 0 0 0 15 1
    2 44 1936 2 2 4 0 1 0 15 1
    2 32 1024 4 2 2 0 1 0 15 1
    1 35 1225 3 2 1 0 0 0 15 1
    1 29  841 6 2 4 0 1 0 15 1
    2 18  324 4 2 3 0 0 0 15 1
    2 56 3136 5 2 4 1 0 0 15 1
    1 35 1225 6 2 3 0 1 0 15 1
    2 41 1681 3 2 4 0 1 0 15 2
    1 63 3969 3 2 4 0 0 0 15 1
    2 36 1296 4 2 2 0 0 0 15 1
    1 46 2116 4 1 4 0 1 0 15 2
    2 40 1600 3 2 2 0 0 0 15 2
    2 63 3969 2 2 2 0 0 0 15 1
    1 71 5041 0 2 4 0 0 0 15 1
    2 36 1296 2 2 3 0 0 0 15 2
    1 34 1156 4 2 4 0 0 0 15 1
    1 36 1296 3 2 1 0 0 0 15 1
    2 67 4489 4 2 2 0 1 0 15 1
    2 21  441 4 1 3 0 1 0 15 1
    2 40 1600 2 2 3 1 0 0 15 1
    1 24  576 2 2 3 0 0 0 15 1
    2 21  441 4 2 3 0 0 0 15 1
    2 18  324 4 2 4 0 1 0 15 2
    2 27  729 4 2 4 0 1 0 15 2
    2 64 4096 2 2 3 0 1 0 15 1
    1 23  529 4 2 5 0 0 0 15 1
    2 41 1681 4 2 1 0 1 0 15 2
    2 28  784 5 1 4 0 1 0 15 2
    1 45 2025 2 1 5 0 1 0 15 2
    2 40 1600 3 1 1 0 1 0 15 2
    2 69 4761 3 2 3 0 1 0 15 2
    2 46 2116 6 2 3 0 1 0 15 1
    2 54 2916 3 2 2 0 1 0 15 2
    1 53 2809 0 2 3 1 0 0 15 1
    2 67 4489 2 2 3 1 0 0 15 1
    1 43 1849 5 2 2 0 1 0 15 1
    1 19  361 4 2 3 0 0 0 15 1
    1 25  625 5 2 3 0 1 0 15 1
    1 73 5329 3 2 4 0 1 0 15 1
    2 20  400 5 2 3 0 1 0 15 1
    1 67 4489 4 2 3 0 0 0 15 1
    2 67 4489 5 1 3 0 1 0 15 2
    2 18  324 5 2 3 0 0 0 15 1
    1 19  361 3 2 2 0 0 0 15 1
    1 58 3364 6 1 4 0 1 0 15 2
    1 41 1681 2 1 4 1 0 0 15 1
    2 59 3481 3 2 3 0 0 0 15 1
    1 20  400 4 2 4 0 1 0 15 2
    2 19  361 4 2 4 0 0 0 15 1
    2 56 3136 3 2 4 0 0 0 15 1
    2 46 2116 5 2 3 0 1 0 15 1
    1 55 3025 2 2 3 1 0 0 15 1
    2 64 4096 2 2 3 0 1 0 15 1
    2 63 3969 0 2 3 0 0 0 15 2
    1 36 1296 5 1 2 0 1 0 15 1
    1 67 4489 4 2 2 0 1 0 15 1
    1 45 2025 5 1 4 0 1 0 15 2
    2 60 3600 4 2 3 0 1 0 15 1
    1 22  484 4 2 3 0 1 0 15 1
    2 20  400 5 2 3 0 0 0 15 1
    1 28  784 3 2 3 0 0 0 15 2
    1 80 6400 0 2 4 0 0 0 15 2
    1 43 1849 9 1 3 0 1 0 15 1
    2 88 7744 6 2 4 1 0 0 15 1
    1 68 4624 2 2 2 0 1 0 15 2
    1 53 2809 3 2 4 0 0 0 15 2
    1 51 2601 2 1 4 0 0 0 15 2
    2 50 2500 2 2 2 0 1 0 15 2
    1 66 4356 0 2 3 0 1 0 15 1
    1 60 3600 3 2 4 0 1 0 15 2
    2 58 3364 4 1 4 0 1 0 15 2
    1 51 2601 2 2 3 0 1 0 15 2
    2 58 3364 2 1 3 0 1 0 15 2
    1 49 2401 4 2 4 0 1 0 15 2
    1 60 3600 2 2 4 1 0 0 15 1
    2 38 1444 4 2 3 0 0 0 15 1
    2 25  625 4 2 3 0 1 0 15 1
    1 40 1600 4 1 4 0 1 0 15 1
    1 20  400 4 2 4 0 0 0 15 1
    1 43 1849 2 2 3 0 0 0 15 1
    1 35 1225 4 2 3 0 1 0 15 1
    2 53 2809 2 1 2 0 1 0 15 2
    1 23  529 4 2 3 0 0 0 15 2
    2 66 4356 0 2 4 0 0 0 15 1
    1 22  484 4 2 4 0 1 0 15 2
    1 19  361 4 1 3 1 0 0 15 2
    1 37 1369 6 2 4 1 0 0 18 1
    1 35 1225 5 2 3 0 0 0 18 1
    2 27  729 2 1 2 0 1 0 18 1
    1 37 1369 8 1 2 0 0 0 18 1
    2 25  625 5 1 3 0 1 0 18 1
    2 47 2209 3 1 3 0 0 0 18 2
    2 35 1225 6 1 2 0 1 0 18 1
    1 33 1089 3 2 4 0 1 0 16 2
    2 19  361 4 1 3 0 0 0 18 1
    2 33 1089 0 2 4 0 1 0 18 2
    1 36 1296 3 2 3 1 0 0 16 2
    1 49 2401 3 1 1 0 0 1 16 2
    1 25  625 3 2 4 0 0 0 16 1
    end
    label values gender LABAR
    label def LABAR 1 "male", modify
    label def LABAR 2 "female", modify
    label values urbrur urbrur
    label def urbrur 1 "urban", modify
    label def urbrur 2 "rural", modify
    label values living_cond LABI
    label def LABI 1 "much worse", modify
    label def LABI 2 "worse", modify
    label def LABI 3 "same", modify
    label def LABI 4 "better", modify
    label def LABI 5 "much better", modify
    label values Country country
    label def country 15 "SOUTH AFRICA", modify
    label def country 16 "TANZANIA", modify
    label def country 18 "ZAMBIA", modify
    label values Wave wave
    label def wave 1 "round3", modify
    label def wave 2 "round4", modify

  • #2
    That won't work with two different x variables as the axis is defined w.r.t. the x variable. If the variables are measured on the same scale, you can reshape long the data and have an indicator identifying which x variable. Then use the -if- qualifier with twoway.

    Comment


    • #3
      Thanks, @Musau for the tip. Do you have a sample code for a similar function? Are you able to show how to include this modification in my code? I have tried several combinations with errors.

      Comment


      • #4
        Give a reproducible example that plots the graphs side-by-side. I do not see the variable "voted_pred_mission" in #1. I am also not interested in the locals and the loops. Your code should be as simple as

        Code:
        lowess y x1 if x2<z
        lowess y x2 if x1<z

        Comment


        • #5
          Sorry for the confusion, the voted_pred_mission is a predicted variable after I run the regression. If you run the regression below, obviously you'll get a different outcome because dataex will not let me add more of my variables. Nonetheless, let's use the original version of the variable, instead of the predicted p,
          lowess voted ldmission , ldmission <= 5.2
          lowess voted ldcatho, ldcatho <= 5.2

          The other problem is that this code generates a graph that has lines running all over. I'm attaching the graphs here for your view. I want to have a smoothened graph


          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input int voted float(ldmission ldcatho) byte gender float(age age2 education) byte(urbrur living_cond) float(catholic_now protestant_now muslim_now) long(Country Wave)
          0  3.295524  5.278751 1 38 1444 2 2 3 0 0 0 15 1
          1 2.3980975  5.266923 2 44 1936 2 2 4 0 1 0 15 1
          1  2.698109  5.303064 2 32 1024 4 2 2 0 1 0 15 1
          1 2.3980975  5.266923 1 35 1225 3 2 1 0 0 0 15 1
          1 2.3062606  5.319501 1 29  841 6 2 4 0 1 0 15 1
          0  2.607949  5.201148 2 18  324 4 2 3 0 0 0 15 1
          1  2.698109  5.303064 2 56 3136 5 2 4 1 0 0 15 1
          1 2.3062606  5.319501 1 35 1225 6 2 3 0 1 0 15 1
          1  1.565786  5.094637 2 41 1681 3 2 4 0 1 0 15 2
          1  2.715725  5.266022 1 63 3969 3 2 4 0 0 0 15 1
          1  2.607949  5.201148 2 36 1296 4 2 2 0 0 0 15 1
          1  2.922326  5.375945 1 46 2116 4 1 4 0 1 0 15 2
          1 1.3604553  5.305167 2 40 1600 3 2 2 0 0 0 15 2
          1 2.1648827  5.224882 2 63 3969 2 2 2 0 0 0 15 1
          1 2.1648827  5.224882 1 71 5041 0 2 4 0 0 0 15 1
          1 1.3604553  5.305167 2 36 1296 2 2 3 0 0 0 15 2
          1 2.7004294  5.314059 1 34 1156 4 2 4 0 0 0 15 1
          1 1.8030276  5.449199 1 36 1296 3 2 1 0 0 0 15 1
          1  3.100268  5.421429 2 67 4489 4 2 2 0 1 0 15 1
          0   2.69352  5.392028 2 21  441 4 1 3 0 1 0 15 1
          1 2.3980975  5.266923 2 40 1600 2 2 3 1 0 0 15 1
          1 2.1882062  5.368993 1 24  576 2 2 3 0 0 0 15 1
          0 2.7004294  5.314059 2 21  441 4 2 3 0 0 0 15 1
          0 2.2233977  5.439286 2 18  324 4 2 4 0 1 0 15 2
          0  1.565786  5.094637 2 27  729 4 2 4 0 1 0 15 2
          1 2.3062606  5.319501 2 64 4096 2 2 3 0 1 0 15 1
          0  3.100268  5.421429 1 23  529 4 2 5 0 0 0 15 1
          1 1.7892542  5.448228 2 41 1681 4 2 1 0 1 0 15 2
          1  2.922326  5.375945 2 28  784 5 1 4 0 1 0 15 2
          1 1.7892542  5.448228 1 45 2025 2 1 5 0 1 0 15 2
          1 1.7892542  5.448228 2 40 1600 3 1 1 0 1 0 15 2
          1  2.724901  5.312489 2 69 4761 3 2 3 0 1 0 15 2
          1 2.3062606  5.319501 2 46 2116 6 2 3 0 1 0 15 1
          1  2.724901  5.312489 2 54 2916 3 2 2 0 1 0 15 2
          0 2.3980975  5.266923 1 53 2809 0 2 3 1 0 0 15 1
          1 2.3980975  5.266923 2 67 4489 2 2 3 1 0 0 15 1
          0   2.56769  5.310072 1 43 1849 5 2 2 0 1 0 15 1
          0  2.607949  5.201148 1 19  361 4 2 3 0 0 0 15 1
          1 2.7004294  5.314059 1 25  625 5 2 3 0 1 0 15 1
          1   2.56769  5.310072 1 73 5329 3 2 4 0 1 0 15 1
          0 2.1882062  5.368993 2 20  400 5 2 3 0 1 0 15 1
          1  3.100268  5.421429 1 67 4489 4 2 3 0 0 0 15 1
          1  2.922326  5.375945 2 67 4489 5 1 3 0 1 0 15 2
          0  3.100268  5.421429 2 18  324 5 2 3 0 0 0 15 1
          0  2.607949  5.201148 1 19  361 3 2 2 0 0 0 15 1
          1  2.162259  5.271806 1 58 3364 6 1 4 0 1 0 15 2
          1 2.1961772  5.272246 1 41 1681 2 1 4 1 0 0 15 1
          1  3.295524  5.278751 2 59 3481 3 2 3 0 0 0 15 1
          0 1.3604553  5.305167 1 20  400 4 2 4 0 1 0 15 2
          0 2.1648827  5.224882 2 19  361 4 2 4 0 0 0 15 1
          1 2.7004294  5.314059 2 56 3136 3 2 4 0 0 0 15 1
          1 1.8030276  5.449199 2 46 2116 5 2 3 0 1 0 15 1
          1 2.3980975  5.266923 1 55 3025 2 2 3 1 0 0 15 1
          1  2.715725  5.266022 2 64 4096 2 2 3 0 1 0 15 1
          1 1.7892542  5.448228 2 63 3969 0 2 3 0 0 0 15 2
          1   2.69352  5.392028 1 36 1296 5 1 2 0 1 0 15 1
          1 1.8030276  5.449199 1 67 4489 4 2 2 0 1 0 15 1
          1 1.7892542  5.448228 1 45 2025 5 1 4 0 1 0 15 2
          1   2.56769  5.310072 2 60 3600 4 2 3 0 1 0 15 1
          0 2.3980975  5.266923 1 22  484 4 2 3 0 1 0 15 1
          1 1.8030276  5.449199 2 20  400 5 2 3 0 0 0 15 1
          1 1.7892542  5.448228 1 28  784 3 2 3 0 0 0 15 2
          1  2.724901  5.312489 1 80 6400 0 2 4 0 0 0 15 2
          1 2.1961772  5.272246 1 43 1849 9 1 3 0 1 0 15 1
          1 2.1882062  5.368993 2 88 7744 6 2 4 1 0 0 15 1
          1  2.724901  5.312489 1 68 4624 2 2 2 0 1 0 15 2
          1  1.565786  5.094637 1 53 2809 3 2 4 0 0 0 15 2
          1  2.162259  5.271806 1 51 2601 2 1 4 0 0 0 15 2
          0 2.2233977  5.439286 2 50 2500 2 2 2 0 1 0 15 2
          1  2.698109  5.303064 1 66 4356 0 2 3 0 1 0 15 1
          1 2.2233977  5.439286 1 60 3600 3 2 4 0 1 0 15 2
          1  2.162259  5.271806 2 58 3364 4 1 4 0 1 0 15 2
          1 2.2233977  5.439286 1 51 2601 2 2 3 0 1 0 15 2
          0  2.162259  5.271806 2 58 3364 2 1 3 0 1 0 15 2
          0  1.565786  5.094637 1 49 2401 4 2 4 0 1 0 15 2
          1  2.715725  5.266022 1 60 3600 2 2 4 1 0 0 15 1
          1  3.295524  5.278751 2 38 1444 4 2 3 0 0 0 15 1
          0 2.3980975  5.266923 2 25  625 4 2 3 0 1 0 15 1
          1   2.69352  5.392028 1 40 1600 4 1 4 0 1 0 15 1
          0 2.1648827  5.224882 1 20  400 4 2 4 0 0 0 15 1
          1 2.1882062  5.368993 1 43 1849 2 2 3 0 0 0 15 1
          1  2.698109  5.303064 1 35 1225 4 2 3 0 1 0 15 1
          1 1.7892542  5.448228 2 53 2809 2 1 2 0 1 0 15 2
          0 1.7892542  5.448228 1 23  529 4 2 3 0 0 0 15 2
          1  2.715725  5.266022 2 66 4356 0 2 4 0 0 0 15 1
          0 1.3604553  5.305167 1 22  484 4 2 4 0 1 0 15 2
          0  2.922326  5.375945 1 19  361 4 1 3 1 0 0 15 2
          1  2.893201  5.572906 1 37 1369 6 2 4 1 0 0 18 1
          1  2.893201  5.572906 1 35 1225 5 2 3 0 0 0 18 1
          0  5.929426  6.401748 2 27  729 2 1 2 0 1 0 18 1
          1    5.7953  6.491528 1 37 1369 8 1 2 0 0 0 18 1
          1    5.7953  6.491528 2 25  625 5 1 3 0 1 0 18 1
          1  5.822277  6.439603 2 47 2209 3 1 3 0 0 0 18 2
          1  5.509483  6.256178 2 35 1225 6 1 2 0 1 0 18 1
          1  5.228532  5.490892 1 33 1089 3 2 4 0 1 0 16 2
          0  5.798994  6.498509 2 19  361 4 1 3 0 0 0 18 1
          0 3.3108175  5.600432 2 33 1089 0 2 4 0 1 0 18 2
          1 2.3856585  5.953181 1 36 1296 3 2 3 1 0 0 16 2
          1  5.046294  4.404323 1 49 2401 3 1 1 0 0 1 16 2
          0  4.090047 4.0036874 1 25  625 3 2 4 0 0 0 16 1
          end
          label values voted voted
          label def voted 0 "No", modify
          label def voted 1 "Yes", modify
          label values gender LABAR
          label def LABAR 1 "male", modify
          label def LABAR 2 "female", modify
          label values urbrur urbrur
          label def urbrur 1 "urban", modify
          label def urbrur 2 "rural", modify
          label values living_cond LABI
          label def LABI 1 "much worse", modify
          label def LABI 2 "worse", modify
          label def LABI 3 "same", modify
          label def LABI 4 "better", modify
          label def LABI 5 "much better", modify
          label values Country country
          label def country 15 "SOUTH AFRICA", modify
          label def country 16 "TANZANIA", modify
          label def country 18 "ZAMBIA", modify
          label values Wave wave
          label def wave 1 "round3", modify
          label def wave 2 "round4", modify
          Attached Files

          Comment


          • #6
            The goodgraph.pdf was produced with the previous code that I shared with the locals, etc.

            Comment


            • #7
              Code:
              * Example generated by -dataex-. For more info, type help dataex
              clear
              input int voted float(ldmission ldcatho) byte gender float(age age2 education) byte(urbrur living_cond) float(catholic_now protestant_now muslim_now) long(Country Wave)
              0  3.295524  5.278751 1 38 1444 2 2 3 0 0 0 15 1
              1 2.3980975  5.266923 2 44 1936 2 2 4 0 1 0 15 1
              1  2.698109  5.303064 2 32 1024 4 2 2 0 1 0 15 1
              1 2.3980975  5.266923 1 35 1225 3 2 1 0 0 0 15 1
              1 2.3062606  5.319501 1 29  841 6 2 4 0 1 0 15 1
              0  2.607949  5.201148 2 18  324 4 2 3 0 0 0 15 1
              1  2.698109  5.303064 2 56 3136 5 2 4 1 0 0 15 1
              1 2.3062606  5.319501 1 35 1225 6 2 3 0 1 0 15 1
              1  1.565786  5.094637 2 41 1681 3 2 4 0 1 0 15 2
              1  2.715725  5.266022 1 63 3969 3 2 4 0 0 0 15 1
              1  2.607949  5.201148 2 36 1296 4 2 2 0 0 0 15 1
              1  2.922326  5.375945 1 46 2116 4 1 4 0 1 0 15 2
              1 1.3604553  5.305167 2 40 1600 3 2 2 0 0 0 15 2
              1 2.1648827  5.224882 2 63 3969 2 2 2 0 0 0 15 1
              1 2.1648827  5.224882 1 71 5041 0 2 4 0 0 0 15 1
              1 1.3604553  5.305167 2 36 1296 2 2 3 0 0 0 15 2
              1 2.7004294  5.314059 1 34 1156 4 2 4 0 0 0 15 1
              1 1.8030276  5.449199 1 36 1296 3 2 1 0 0 0 15 1
              1  3.100268  5.421429 2 67 4489 4 2 2 0 1 0 15 1
              0   2.69352  5.392028 2 21  441 4 1 3 0 1 0 15 1
              1 2.3980975  5.266923 2 40 1600 2 2 3 1 0 0 15 1
              1 2.1882062  5.368993 1 24  576 2 2 3 0 0 0 15 1
              0 2.7004294  5.314059 2 21  441 4 2 3 0 0 0 15 1
              0 2.2233977  5.439286 2 18  324 4 2 4 0 1 0 15 2
              0  1.565786  5.094637 2 27  729 4 2 4 0 1 0 15 2
              1 2.3062606  5.319501 2 64 4096 2 2 3 0 1 0 15 1
              0  3.100268  5.421429 1 23  529 4 2 5 0 0 0 15 1
              1 1.7892542  5.448228 2 41 1681 4 2 1 0 1 0 15 2
              1  2.922326  5.375945 2 28  784 5 1 4 0 1 0 15 2
              1 1.7892542  5.448228 1 45 2025 2 1 5 0 1 0 15 2
              1 1.7892542  5.448228 2 40 1600 3 1 1 0 1 0 15 2
              1  2.724901  5.312489 2 69 4761 3 2 3 0 1 0 15 2
              1 2.3062606  5.319501 2 46 2116 6 2 3 0 1 0 15 1
              1  2.724901  5.312489 2 54 2916 3 2 2 0 1 0 15 2
              0 2.3980975  5.266923 1 53 2809 0 2 3 1 0 0 15 1
              1 2.3980975  5.266923 2 67 4489 2 2 3 1 0 0 15 1
              0   2.56769  5.310072 1 43 1849 5 2 2 0 1 0 15 1
              0  2.607949  5.201148 1 19  361 4 2 3 0 0 0 15 1
              1 2.7004294  5.314059 1 25  625 5 2 3 0 1 0 15 1
              1   2.56769  5.310072 1 73 5329 3 2 4 0 1 0 15 1
              0 2.1882062  5.368993 2 20  400 5 2 3 0 1 0 15 1
              1  3.100268  5.421429 1 67 4489 4 2 3 0 0 0 15 1
              1  2.922326  5.375945 2 67 4489 5 1 3 0 1 0 15 2
              0  3.100268  5.421429 2 18  324 5 2 3 0 0 0 15 1
              0  2.607949  5.201148 1 19  361 3 2 2 0 0 0 15 1
              1  2.162259  5.271806 1 58 3364 6 1 4 0 1 0 15 2
              1 2.1961772  5.272246 1 41 1681 2 1 4 1 0 0 15 1
              1  3.295524  5.278751 2 59 3481 3 2 3 0 0 0 15 1
              0 1.3604553  5.305167 1 20  400 4 2 4 0 1 0 15 2
              0 2.1648827  5.224882 2 19  361 4 2 4 0 0 0 15 1
              1 2.7004294  5.314059 2 56 3136 3 2 4 0 0 0 15 1
              1 1.8030276  5.449199 2 46 2116 5 2 3 0 1 0 15 1
              1 2.3980975  5.266923 1 55 3025 2 2 3 1 0 0 15 1
              1  2.715725  5.266022 2 64 4096 2 2 3 0 1 0 15 1
              1 1.7892542  5.448228 2 63 3969 0 2 3 0 0 0 15 2
              1   2.69352  5.392028 1 36 1296 5 1 2 0 1 0 15 1
              1 1.8030276  5.449199 1 67 4489 4 2 2 0 1 0 15 1
              1 1.7892542  5.448228 1 45 2025 5 1 4 0 1 0 15 2
              1   2.56769  5.310072 2 60 3600 4 2 3 0 1 0 15 1
              0 2.3980975  5.266923 1 22  484 4 2 3 0 1 0 15 1
              1 1.8030276  5.449199 2 20  400 5 2 3 0 0 0 15 1
              1 1.7892542  5.448228 1 28  784 3 2 3 0 0 0 15 2
              1  2.724901  5.312489 1 80 6400 0 2 4 0 0 0 15 2
              1 2.1961772  5.272246 1 43 1849 9 1 3 0 1 0 15 1
              1 2.1882062  5.368993 2 88 7744 6 2 4 1 0 0 15 1
              1  2.724901  5.312489 1 68 4624 2 2 2 0 1 0 15 2
              1  1.565786  5.094637 1 53 2809 3 2 4 0 0 0 15 2
              1  2.162259  5.271806 1 51 2601 2 1 4 0 0 0 15 2
              0 2.2233977  5.439286 2 50 2500 2 2 2 0 1 0 15 2
              1  2.698109  5.303064 1 66 4356 0 2 3 0 1 0 15 1
              1 2.2233977  5.439286 1 60 3600 3 2 4 0 1 0 15 2
              1  2.162259  5.271806 2 58 3364 4 1 4 0 1 0 15 2
              1 2.2233977  5.439286 1 51 2601 2 2 3 0 1 0 15 2
              0  2.162259  5.271806 2 58 3364 2 1 3 0 1 0 15 2
              0  1.565786  5.094637 1 49 2401 4 2 4 0 1 0 15 2
              1  2.715725  5.266022 1 60 3600 2 2 4 1 0 0 15 1
              1  3.295524  5.278751 2 38 1444 4 2 3 0 0 0 15 1
              0 2.3980975  5.266923 2 25  625 4 2 3 0 1 0 15 1
              1   2.69352  5.392028 1 40 1600 4 1 4 0 1 0 15 1
              0 2.1648827  5.224882 1 20  400 4 2 4 0 0 0 15 1
              1 2.1882062  5.368993 1 43 1849 2 2 3 0 0 0 15 1
              1  2.698109  5.303064 1 35 1225 4 2 3 0 1 0 15 1
              1 1.7892542  5.448228 2 53 2809 2 1 2 0 1 0 15 2
              0 1.7892542  5.448228 1 23  529 4 2 3 0 0 0 15 2
              1  2.715725  5.266022 2 66 4356 0 2 4 0 0 0 15 1
              0 1.3604553  5.305167 1 22  484 4 2 4 0 1 0 15 2
              0  2.922326  5.375945 1 19  361 4 1 3 1 0 0 15 2
              1  2.893201  5.572906 1 37 1369 6 2 4 1 0 0 18 1
              1  2.893201  5.572906 1 35 1225 5 2 3 0 0 0 18 1
              0  5.929426  6.401748 2 27  729 2 1 2 0 1 0 18 1
              1    5.7953  6.491528 1 37 1369 8 1 2 0 0 0 18 1
              1    5.7953  6.491528 2 25  625 5 1 3 0 1 0 18 1
              1  5.822277  6.439603 2 47 2209 3 1 3 0 0 0 18 2
              1  5.509483  6.256178 2 35 1225 6 1 2 0 1 0 18 1
              1  5.228532  5.490892 1 33 1089 3 2 4 0 1 0 16 2
              0  5.798994  6.498509 2 19  361 4 1 3 0 0 0 18 1
              0 3.3108175  5.600432 2 33 1089 0 2 4 0 1 0 18 2
              1 2.3856585  5.953181 1 36 1296 3 2 3 1 0 0 16 2
              1  5.046294  4.404323 1 49 2401 3 1 1 0 0 1 16 2
              0  4.090047 4.0036874 1 25  625 3 2 4 0 0 0 16 1
              end
              label values voted voted
              label def voted 0 "No", modify
              label def voted 1 "Yes", modify
              label values gender LABAR
              label def LABAR 1 "male", modify
              label def LABAR 2 "female", modify
              label values urbrur urbrur
              label def urbrur 1 "urban", modify
              label def urbrur 2 "rural", modify
              label values living_cond LABI
              label def LABI 1 "much worse", modify
              label def LABI 2 "worse", modify
              label def LABI 3 "same", modify
              label def LABI 4 "better", modify
              label def LABI 5 "much better", modify
              label values Country country
              label def country 15 "SOUTH AFRICA", modify
              label def country 16 "TANZANIA", modify
              label def country 18 "ZAMBIA", modify
              label values Wave wave
              label def wave 1 "round3", modify
              label def wave 2 "round4", modify
              
              set scheme s1color
              tw lowess voted ldmission if ldmission <= 5.2, sort lc(blue) saving(gr1, replace)
              tw lowess voted ldcatho if ldcatho <= 5.2, sort lc(red) saving(gr2, replace)
              
              rename (ldmission ldcatho) var=
              gen long id=_n
              reshape long var, i(id) j(which) string
              tw lowess voted var if var <= 5.2 & which=="ldmission", sort lc(blue) || ///
                 lowess voted var if var <= 5.2 & which=="ldcatho", sort lc(red)  ///
                 xtitle("Something informative") leg(off) saving(gr3, replace)
                 
              gr combine gr1.gph gr2.gph gr3.gph
              Res.:

              Click image for larger version

Name:	Graph.png
Views:	1
Size:	31.9 KB
ID:	1729569



              Comment


              • #8
                @Musau, sorry, I meant to say thank you much earlier. This is what I needed.

                Comment

                Working...
                X