Announcement

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

  • Number of "bins" with rddensity, plot

    After rddensity, plot, I cannot figure out (1) the number of bins drawn by rddensity, plot (other than manually counting the number of rectangles on the graph),
    (2) and the lowest x-value and highest x-values for the bins. Any suggestions? Example of rddensity, plot below. In this example there seem to be about 50 bins, the lowest x-value is about 0.05, and the highest x-value is 1.

    clear all
    use https://sscc.wisc.edu/~rdimond/real_world_tables/reg3
    gen x = runiform(0,1)
    gen y = 0.9*x + 0.1*nicu
    rddensity y, c(0.5) plot

  • #2
    rddensity is from SSC, as you are asked to explain in FAQ Advice #12. You can ask for the estimation results to be generated.

    Code:
    clear all
    use https://sscc.wisc.edu/~rdimond/real_world_tables/reg3
    gen x = runiform(0,1)
    gen y = 0.9*x + 0.1*nicu
    rddensity y, c(0.5) plot genvars(z)
    
    *(1) the number of bins drawn by rddensity
    count if !missing(z_hist_height)
    
    *(2) and the lowest x-value and highest x-values for the bins
    sum z_hist_height
    Res.:
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	121.4 KB
ID:	1783831


    Code:
    . *(1) the number of bins drawn by rddensity
    
    .
    . count if !missing(z_hist_height)
      74
    
    .
    .
    .
    . *(2) and the lowest x-value and highest x-values for the bins
    
    .
    . sum z_hist_height
    
        Variable |        Obs        Mean    Std. dev.       Min        Max
    -------------+---------------------------------------------------------
    z_hist_hei~t |         74    1.016774    .2141698   .5255579   1.348446

    Comment


    • #3
      My bad. Thank you so much for your help!

      Comment


      • #4
        Under further thought, the lowest x-value and highest x-values for the bins do not seem right at all. The command you gives
        .5255579 1.348446 while by looking at the picture, it should be 0.05 1.

        Comment


        • #5
          Reading the help more carefully, the lower and upper bounds are

          di e(c) - e(h_l)*3
          di e(c) + e(h_h)*3

          Comment


          • #6
            Originally posted by Richard Thomas Boylan View Post
            Under further thought, the lowest x-value and highest x-values for the bins do not seem right at all. The command you gives
            .5255579 1.348446 while by looking at the picture, it should be 0.05 1.
            Ah yes. The values represent the max and min heights of the bars "y-values". For the x-values, either jointly evaluate the minimum of z_hist_endl and the maximum of z_hist_endr or the min and max values of z_grid (preferable).

            Code:
            clear all
            use https://sscc.wisc.edu/~rdimond/real_world_tables/reg3
            gen x = runiform(0,1)
            gen y = 0.9*x + 0.1*nicu
            rddensity y, c(0.5) plot genvars(z)
            
            *(1) the number of bins drawn by rddensity
            count if !missing(z_hist_height)
            
            *(2) and the lowest x-value and highest x-values for the bins
            sum z_hist_endl z_hist_endr
            
            *OR PREFERABLY
            sum z_grid
            Res.:

            Code:
            . 
            . sum z_hist_endl z_hist_endr
            
                Variable |        Obs        Mean    Std. dev.       Min        Max
            -------------+---------------------------------------------------------
             z_hist_endl |         74    .5032266    .2790622   .0390249   .9863403
             z_hist_endr |         74    .5162107    .2795202   .0514837   .9998498
            
            . 
            . 
            . 
            . *OR PREFERABLY
            
            . 
            . sum z_grid
            
                Variable |        Obs        Mean    Std. dev.       Min        Max
            -------------+---------------------------------------------------------
                  z_grid |         20    .5097187     .292439   .0390249   .9998498

            But the bars have widths, so these represent the starting and ending values. If you want the min and max of the bars' centers:

            Code:
            sum z_hist_center
            and with this, you get:

            Code:
            . sum z_hist_center
            
                Variable |        Obs        Mean    Std. dev.       Min        Max
            -------------+---------------------------------------------------------
            z_hist_cen~r |         75     .480327    .2715404   .0066127    .927862

            Comment

            Working...
            X