Announcement

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

  • #16
    What about this? I have generated a new variable AMc which is equal to the variable AM so that -xchart- can be used. It does not change the results. Now, the 0's are not in the calculation of the lower and the upper limits but they are plotted in the graphs where they appear as out of limits.

    I think it is impossible to control the number of days in the x-axis; the graph of every week starts from day 1.

    Code:
    gen AMc = AM
    levelsof week, local(levels)
    foreach i of local levels {
        
        preserve
        keep if week == `i'
        qui sum AM , detail
        local x = r(mean)
        display `x'
        local s = r(sd)
        display `s'
        local u =`x'+(3*`s')
        display `u'
        local t =`x'-(3*`s')
        display `t'
        local z =`x'-(100*`s')
    
        replace AM=0 if AM==.
        replace AMc=0 if AMc==.
        xchart AM AMc , lower(`t') upper(`u') connect(l ) saving(graph`i', replace)
        local total`i' = r(N)
        local violations`i' = r(out_x)
        local AMscore`i' = (1-(`violations`i''/`total`i''))*100
        display `AMscore`i''
        restore
     }
    Abraham

    Comment


    • #17
      Hi Abraham

      That's a really good solution. One problem, i'd like so save the output AMscore`i' as a new variable? i'm not sure how you can do that with the preserve and restore options.

      thanks
      imran

      Comment


      • #18

        The following code generate the AMscore variables.

        Code:
        gen AMc = AM
        levelsof week, local(levels)
        foreach i of local levels {
           
            preserve
            keep if week == `i'
            qui sum AM , detail
            local x = r(mean)
            display `x'
            local s = r(sd)
            display `s'
            local u =`x'+(3*`s')
            display `u'
            local t =`x'-(3*`s')
            display `t'
            local z =`x'-(100*`s')
            replace AM=0 if AM==.
            replace AMc=0 if AMc==. 
            xchart AM AMc , lower(`t') upper(`u') connect(l) saving(graph`i', replace)
            restore
         
            local total`i' = r(N)
            local violations`i' = r(out_x)
            local AMscore`i' = (1-(`violations`i''/`total`i''))*100
            display `AMscore`i''
            gen AMscore`i' = `AMscore`i''
         
         }

        Comment


        • #19
          Just being picky, but various minute simplifications are possible to

          Code:
            
          qui sum AM , detail
          local x = r(mean)
          display `x'
          local s = r(sd)
          display `s'
          local u =`x'+(3*`s')
          display `u'
          local t =`x'-(3*`s')
          display `t'
          local z =`x'-(100*`s')
          If all you want are mean and SD, you don't need the detail option. If you want to show those, then suppress the quietly. There is no point to creating a local macro you don't use. So we should be able to go

          Code:
          sum AM  
          local u = r(mean) + 3 * r(sd)  
          local t = r(mean) - 3 * r(sd)  
          display "lower `t' upper `u'"
          Last edited by Nick Cox; 28 Oct 2014, 08:54.

          Comment


          • #20
            Thanks Nick. That is also easy to read.
            Last edited by Abraham Wolde-Tsadick; 28 Oct 2014, 08:35.

            Comment


            • #21
              thanks Nick and Abraham, that's great advice and it works perfectly

              I have to further questions:
              1. How do i remove the data that's preserved by the preserve function; if i try and run the code above a second time i get the error data preserved already
              2. Does anyone know how to run control charts with the Western Electric Rules??

              thanks a lot
              imran

              Comment


              • #22
                Also,

                Does anyone have any idea how to alter the color of violations in the control chart to say a red marker?

                thanks
                imran

                Comment


                • #23
                  any suggestions anyone?

                  thanks
                  imran

                  Comment

                  Working...
                  X