Announcement

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

  • marginscontplot problem.

    Dear All, I have a dataset with two variables (simplified). The basic statistics
    Code:
    . sum indep ir2d1
    
        Variable |        Obs        Mean    Std. Dev.       Min        Max
    -------------+---------------------------------------------------------
           indep |     35,432    .3323226    .1119013          0   .5555556
           ir2d1 |     34,059    .5667652    .1640421   .2095384   .9267846
    When I use, say the first 1,000 observations, the command marginscontplot works and gives me the figure. However, when I increase to say, 10,000, the estimation result is
    Code:
    . keep in 1/10000
    (47,372 observations deleted)
    
    . reg indep ir2d1 c.ir2d1#c.ir2d1, 
    
          Source |       SS           df       MS      Number of obs   =     8,888
    -------------+----------------------------------   F(2, 8885)      =      5.93
           Model |  .218049191         2  .109024596   Prob > F        =    0.0027
        Residual |  163.360103     8,885  .018386056   R-squared       =    0.0013
    -------------+----------------------------------   Adj R-squared   =    0.0011
           Total |  163.578153     8,887  .018406454   Root MSE        =     .1356
    
    ---------------------------------------------------------------------------------
              indep |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    ----------------+----------------------------------------------------------------
              ir2d1 |   .1730636   .0502702     3.44   0.001     .0745223    .2716048
                    |
    c.ir2d1#c.ir2d1 |  -.1495413   .0442941    -3.38   0.001    -.2363681   -.0627146
                    |
              _cons |   .2565559   .0135907    18.88   0.000      .229915    .2831968
    ---------------------------------------------------------------------------------
    and error message is
    Code:
    . marginscontplot ir2d1, ci
    invalid numlist has too many elements
    r(123);
    It seems to me that this mcp/marginscontplot can not be applied to a large dataset? Any suggestions? Thanks.
    Ho-Chuan (River) Huang
    Stata 17.0, MP(4)

  • #2
    By the way, please search marginscontplot and install.
    Ho-Chuan (River) Huang
    Stata 17.0, MP(4)

    Comment


    • #3
      marginscontplot is written by Patrick Royston, the Stata Journal article that goes with this command is https://www.stata-journal.com/articl...article=gr0056.

      Consider using the at1() option to specify at which values to compute and plot the marginal predictions.

      Here is a simple example using simulated data:

      Code:
      set seed 12345
      set obs 10000
      gen x = rnormal()
      gen y = x - x*x + 1 + rnormal()
      regress y c.x##c.x
      
      * following throws and error because of too many values
      cap noi marginscontplot x
      
      * specify at which values of 'x' to compute the marginal predictions
      marginscontplot x, at1(.2(.01).9)
      Here is a log of the output

      Code:
      . set seed 12345
      
      . set obs 10000
      number of observations (_N) was 0, now 10,000
      
      . gen x = rnormal()
      
      . gen y = x - x*x + 1 + rnormal()
      
      . regress y c.x##c.x
      
            Source |       SS           df       MS      Number of obs   =    10,000
      -------------+----------------------------------   F(2, 9997)      =  14625.92
             Model |  29811.7737         2  14905.8868   Prob > F        =    0.0000
          Residual |  10188.3632     9,997  1.01914206   R-squared       =    0.7453
      -------------+----------------------------------   Adj R-squared   =    0.7452
             Total |  40000.1369     9,999  4.00041373   Root MSE        =    1.0095
      
      ------------------------------------------------------------------------------
                 y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
                 x |   1.010405   .0101316    99.73   0.000     .9905454    1.030265
                   |
           c.x#c.x |  -1.006517   .0071026  -141.71   0.000    -1.020439   -.9925941
                   |
             _cons |   1.022298   .0123168    83.00   0.000     .9981551    1.046442
      ------------------------------------------------------------------------------
      
      . cap noi marginscontplot x
      invalid numlist has too many elements
      
      . marginscontplot x, at1(.2(.01).9)
      Here is the resulting graph.

      Click image for larger version

Name:	marginscontplot.png
Views:	1
Size:	17.7 KB
ID:	1483837

      Comment


      • #4
        Dear Jeff, Thank you so much. The code works quite well.
        Ho-Chuan (River) Huang
        Stata 17.0, MP(4)

        Comment

        Working...
        X