Announcement

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

  • How to create combination two way normal distribution data?

    I have two groups of data that describe groups with treatment (dummyG=1) and without treatment(dummyG=0). And I want to make combination normal distribution data. I have already succeed create graph with only 1 normal distribution with this command
    [histogram pengh_nett if dummyG==1 , frequency normal ]
    [histogram pengh_nett if dummyG==0, frequency normal ]
    So how to combine both of graph?


  • #2
    Code:
    histogram pengh_nett, by(dummyG) frequency normal

    Comment


    • #3
      Originally posted by Clyde Schechter View Post
      Code:
      histogram pengh_nett, by(dummyG) frequency normal
      Sorry Clyde, but it doesn't work and there is a response from STATA like this:
      "option frequency may not be combined with the normal and by() option"

      How should I dealt with?

      Comment


      • #4
        Originally posted by andre prast View Post
        So how to combine both of graph?
        Maybe, er, graph combine?
        Code:
        sysuse auto
        histogram mpg if foreign, frequency normal name(A)
        histogram mpg if !foreign, frequency normal name(B)
        graph combine A B, ycommon xcommon

        Comment


        • #5
          thanks for the response, but I mean overlay both of graph in one plot, not side by side.
          Thanks

          Comment


          • #6
            Side-by-side will allow you to see which histogram each normal density overlay belongs to. What you're asking for sounds like it would be a mess.

            Comment


            • #7
              Originally posted by Joseph Coveney View Post
              Side-by-side will allow you to see which histogram each normal density overlay belongs to. What you're asking for sounds like it would be a mess.
              Well, not necessarily a mess...

              https://roastata.wordpress.com/2017/...rams-in-stata/
              Be aware that it can be very hard to answer a question without sample data. You can use the dataex command for this. Type help dataex at the command line.

              When presenting code or results, please use the code delimiters format them. Use the # button on the formatting toolbar, between the " (double quote) and <> buttons.

              Comment


              • #8
                Thanks Weiwen..

                Comment


                • #9
                  Originally posted by Weiwen Ng View Post
                  Well, not necessarily a mess...
                  That doesn't have the two normal overlays. The OP wants four plots (two histograms and two normal density) overlaid on a graph.

                  .ÿsysuseÿauto
                  (1978ÿAutomobileÿData)

                  .ÿgraphÿtwowayÿ///
                  >ÿÿÿÿÿÿÿÿÿhistogramÿmpgÿifÿforeign,ÿfrequencyÿnormalÿlcolor(gs12)ÿfcolor(gs12)ÿ||ÿ///
                  >ÿÿÿÿÿÿÿÿÿhistogramÿmpgÿifÿ!foreign,ÿfrequencyÿnormalÿfcolor(none)ÿlcolor(red)ÿ///
                  >ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿlegend(off)ÿxtitle("foreignÿ(red:ÿdomestic)")
                  optionÿnormalÿnotÿallowed
                  r(198);

                  Comment


                  • #10
                    Perhaps this would help.

                    Code:
                    sysuse auto, clear
                    
                    quietly summarize mpg if foreign
                    local var1mean: display %6.2f r(mean)
                    local var1sd: display %6.2f r(sd)
                    local var1min: display %6.2f r(min)
                    local var1max: display %6.2f r(max)
                    quietly summarize mpg if !foreign
                    local var2mean : display %6.2f r(mean)
                    local var2sd: display %6.2f r(sd)
                    local var2min: display %6.2f r(min)
                    local var2max: display %6.2f r(max)
                    
                    twoway /// 
                      (histogram mpg if !foreign, start(10) width(2) fraction bfcolor(brown%20) blcolor(brown)) /// 
                      (histogram mpg if foreign, fraction start(10) width(2) barw(1.8) bfcolor(navy%20) blcolor(navy)) /// 
                      (function y=normalden(x, `var1mean', `var1sd') , range(`var1min' `var1max') lcolor(navy)) /// 
                      (function y=normalden(x, `var2mean', `var2sd') , range(`var2min' `var2max') lcolor(brown)) ///
                       , xlabel(10(5)45, labsize(small)) ylabel(, angle(horizontal) labsize(vsmall) format(%3.2f)) /// 
                       legend(order(1 "Domestic" 2 "Foreign") pos(2) ring(0) col(1)) /// 
                       note(" " "MPG Domestic:  {it:M} = `var2mean'  {it:SD} = `var2sd'" /// 
                       "MPG Foreign:     {it:M} = `var1mean'  {it:SD} = `var1sd'", size(vsmall)) /// 
                       scheme(s1color) name(HistPlusNormal, replace)
                    Red Owl
                    Stata/IC 15.1, Windows 10 (64 bit)

                    Comment


                    • #11
                      Very nice. He wants the one on the left.
                      Code:
                      // Adapted and extended from Red Owl's
                      
                      clear *
                      
                      sysuse auto
                      
                      quietly summarize mpg if foreign
                      local var1mean: display %6.2f r(mean)
                      local var1sd: display %6.2f r(sd)
                      local var1min: display %6.2f r(min)
                      local var1max: display %6.2f r(max)
                      quietly summarize mpg if !foreign
                      local var2mean : display %6.2f r(mean)
                      local var2sd: display %6.2f r(sd)
                      local var2min: display %6.2f r(min)
                      local var2max: display %6.2f r(max)
                      
                      graph twoway ///
                        (histogram mpg if !foreign, start(10) width(2) frequency bfcolor(brown%20) blcolor(brown)) ///
                        (histogram mpg if foreign, frequency start(10) width(2) barw(1.8) bfcolor(navy%20) blcolor(navy)) ///
                        (function y=normalden(x, `var1mean', `var1sd')  * `var1max' , range(`var1min' `var1max') lcolor(navy)) ///
                        (function y=normalden(x, `var2mean', `var2sd') * `var2max' , range(`var2min' `var2max') lcolor(brown)) ///
                         , xlabel(10(5)45, labsize(small)) ylabel(, angle(horizontal) labsize(vsmall) format(%3.0f)) ///
                         legend(order(1 "Domestic" 2 "Foreign") pos(2) ring(0) col(1)) ///
                         note(" " "MPG Domestic:  {it:M} = `var2mean'  {it:SD} = `var2sd'" ///
                         "MPG Foreign:     {it:M} = `var1mean'  {it:SD} = `var1sd'", size(vsmall)) ///
                         scheme(s1color) name(HistPlusNormal1)
                       
                      graph twoway ///
                        (histogram mpg if !foreign, start(10) width(2) fraction bfcolor(brown%20) blcolor(brown)) ///
                        (histogram mpg if foreign, fraction start(10) width(2) barw(1.8) bfcolor(navy%20) blcolor(navy)) ///
                        (function y=normalden(x, `var1mean', `var1sd') , range(`var1min' `var1max') lcolor(navy)) ///
                        (function y=normalden(x, `var2mean', `var2sd') , range(`var2min' `var2max') lcolor(brown)) ///
                         , xlabel(10(5)45, labsize(small)) ylabel(, angle(horizontal) labsize(vsmall) format(%3.2f)) ///
                         legend(order(1 "Domestic" 2 "Foreign") pos(2) ring(0) col(1)) ///
                         note(" " "MPG Domestic:  {it:M} = `var2mean'  {it:SD} = `var2sd'" ///
                         "MPG Foreign:     {it:M} = `var1mean'  {it:SD} = `var1sd'", size(vsmall)) ///
                         scheme(s1color) name(HistPlusNormal2)
                        
                       graph combine HistPlusNormal1 HistPlusNormal2, xcommon
                      Maybe as a textbook cover illustration, but for work-a-day use in interpretation, #4 would be about as far as I would have gone.

                      Comment

                      Working...
                      X