Announcement

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

  • Problem with nlsur command

    Dear Stata users,

    I am currently running the nlsur command to estimate a system of 2 equations using the following syntax:

    Code:
    nlsur (c_fsinc = {a0} + {a1}*c_stacc + {a2}*c_stocf)(c_sizeret = {beta1}*(c_fsinc -{a0s}-{a1s}*c_stacc - {a2s}*c_stocf)), vce(cluster time)
    The equation (1) is the forecasting equation: c_fsinc = {a0} + {a1}*c_stacc + {a2}*c_stocf
    The equation (2) is the pricing equation: c_sizeret = {beta1}*(c_fsinc -{a0s}-{a1s}*c_stacc - {a2s}*c_stocf

    and this is what I got:

    Code:
    Calculating NLS estimates...
    could not evaluate equation 1
    starting values invalid or some RHS variables have missing values
    r(480);
    I am new to Stata and I am not sure how to fix this error. As I knew that Stata excludes missing values when regressing, so I guess there might be something to do with the initial values.

    I am not sure about how to proceed from here. Any help and suggestion will be very much appreciated.

    Sincerely yours,

    Khanh

    This is the data generated by -dataex-:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int(unit_id time) float(c_fsinc c_stacc c_stocf c_sizeret)
    1 2000   11.095           .   44.008   3.044987
    1 2001    5.583   -.0874317    5.224  -.1652283
    1 2002    3.861   .29353163  -42.801  -.4231709
    1 2003   -4.064  -.15650004  10.2003 -.54456735
    1 2004  -13.577   .02961883   -8.937 -.29095754
    1 2005    .6989  -.27193496    7.805   3.436494
    1 2006  -9.2673  -.14769301   4.6517   3.818903
    1 2007 -11.1224  -.14354037  -8.7062   5.257833
    1 2008   2.4688   -.0722658  -1.1474  3.1859944
    1 2009  11.6241   -.1986534  45.4037   1.705382
    1 2010   2.9899   .11853852 -11.8675   .1003933
    1 2011   2.0053  -.05195754  19.3657  -.4316798
    1 2012  -1.0334   .16627726  17.5627 -.09248185
    1 2013   3.8014   .02308112 -21.0423   .3205987
    1 2014   1.2471   .09067812  -5.5341  .23287398
    1 2015  39.2993  .003675696   9.4619    1.84437
    1 2016   8.5667   -.2839655  140.423 -.12539318
    1 2017        .  -.12699409  14.4395  -.6051657
    2 2000 -124.622   .20785487   9.1339  1.8036478
    2 2001   -10.71   -.3467585  -5.3689  -.8658409
    2 2002     .987    .0822746     .317  -.3857885
    2 2003   38.588     .019928   15.924 -.29408288
    2 2004   -5.266    .4997058   -9.562  .10540456
    2 2005  -1.7561  -.24746884     14.5  3.3120015
    2 2006   1.6822   .10150523   6.1509   3.854261
    2 2007     .748  -.15123634  12.9634     5.8056
    2 2008    .3135   .08393575   1.4254   3.184806
    2 2009    .8889  .034479022   4.1066   5.606124
    2 2010  33.9895  -.14203873    -.385  -.1284118
    2 2011   39.129  -.25330418  103.386 -.04299143
    2 2012   22.758  -.04573207  86.7555   3.895035
    2 2013   7.7678  -.02250768  66.8851    .845217
    2 2014  185.671  -.08318695  69.7514   5.885801
    2 2015  521.866    .3290931 -62.7312   7.409277
    2 2016  873.781   .18091014 -39.1415   4.887175
    2 2017        .    .1497909 -15.7663   4.142799
    3 2000  26.6242  -.20521878  -33.397   5.215007
    3 2001  13.5809  -.05240782  240.861   4.782817
    3 2002    12.91   .04881822   14.756   5.120404
    3 2003   16.844   .04537622  -39.653   4.996433
    3 2004  71.8039  -.05788913   43.242   4.856194
    3 2005  135.634   -.0755362  429.297  4.0577707
    3 2006  230.389  -.06104685  129.678    5.03461
    3 2007  200.381   .05176217  -232.24   7.855485
    3 2008   253.46   .04361181  554.182  3.6344376
    3 2009  325.476  -.04361504  515.166   6.992318
    3 2010  269.923    .1736856 -654.929    5.62332
    3 2011  160.461    .1279638 -1120.65  4.7459702
    3 2012    292.4  .014459985 -72.1783   4.903387
    3 2013  303.325 -.005289631 -299.214   5.330762
    3 2014  750.495 .0012534356  170.046   6.734075
    3 2015  233.384    .1027608 -383.128   5.482848
    3 2016  133.204   .12325507 -388.045   4.874717
    3 2017        .   .01924204 -160.627   4.081945
    4 2000    1.755           .  -28.226   .7562572
    4 2001   12.143           .   22.629  -.3611049
    4 2002    7.031  .021934465   50.347   3.599008
    4 2003  -14.997    .1994297 -157.781   3.511429
    4 2004 -81.2912   -.1859179  -14.998  3.6600254
    4 2005   4.1603   -.2982836   3.5313     3.4637
    4 2006 -28.8689   .16106696   3.8836  1.0714513
    4 2007  15.8154  -.15661116  22.3851  2.0610507
    4 2008   7.3919  .070336886   3.6043  -.7715604
    4 2009  -1.0431  .001318937  12.0977   1.194843
    4 2010   5.0148  .011088284 -10.3319  .12995148
    4 2011  37.8202  .016581232   5.0777  .16719593
    4 2012   3.1401   .22159834  -8.2186   1.892415
    4 2013 -74.5532  .031706214    .7513   3.841636
    4 2014  33.4436   -.0662543 -118.064  1.5790174
    4 2015  39.8771    .3191679 -410.522  2.3134086
    4 2016 -1061.43   .05887472 -182.278    1.70993
    4 2017        .   .04516191   513.08   3.060521
    5 2000  153.207   -.4568579  292.581   7.921634
    5 2001  162.802  -.04799785  308.812   3.682178
    5 2002  202.632  -.04271837  285.899   2.334574
    5 2003  337.806  -.04614428   395.42   2.427877
    5 2004  316.411  -.05078634  532.241  4.3948708
    5 2005  332.112  -.04960303  532.241   3.995865
    5 2006  431.485  -.18311357  665.837   6.477026
    5 2007   420.08   .04067595  906.812  3.5393586
    5 2008  831.944  -.07130431  800.488  2.0022154
    5 2009  1455.21   -.0417543  1502.44   5.509697
    5 2010  1178.23  -.02768715  2229.47   4.916965
    5 2011  274.746  -.05705725  1461.88   2.061875
    5 2012  1535.93  -.04438705  1444.83  4.1144814
    5 2013  873.653  -.02075426  1456.53  2.5898175
    5 2014  532.653  -.06572313  1196.18   .9744867
    5 2015  797.722  -.04347397  1096.23  3.1049085
    5 2016  825.388  -.03354574  1956.05  2.4525535
    5 2017        .  -.07137262  2115.06   2.308459
    6 2000 -707.018     .358442  229.842   .9246945
    6 2001   43.123  -.29042542  1805.72  .42337635
    6 2002  101.071  -.06911801  963.539    .701834
    6 2003  142.549   .18138306  345.782   .8659249
    6 2004   19.552   .08003017 -354.695   .6883366
    6 2005  96.7749  -.05598192  -81.535   .5126982
    6 2006  207.092   .06734498  178.829  1.0426645
    6 2007   267.68  -.05472161 -25.5691  2.0497851
    6 2008  151.671  -.08230114  277.008   .5703058
    6 2009  83.9479 -.017399611  263.371  2.3021162
    end
    Last edited by Khanh Hoang; 30 Jan 2019, 17:46.

  • #2
    This is something new for me as well, but apparently -nlsur- cannot handle missing values. So you need to manually take care of the missing values.

    This is what I did:

    Code:
    . qui reg c_fsinc c_stacc c_stocf
    
    . keep if e(sample)
    (8 observations deleted)
    
    . nlsur (c_fsinc = {a0} + {a1}*c_stacc + {a2}*c_stocf)(c_sizeret = {beta1}*(c_fsinc -{a0s}-{a1s}*c_st
    > acc - {a2s}*c_stocf)), vce(cluster time)
    (obs = 92)
    
    Calculating NLS estimates...
    Iteration 0:  Residual SS =   7025416
    Iteration 1:  Residual SS =   7024966
    Iteration 2:  Residual SS =   7024938
    Iteration 3:  Residual SS =   7024938
    Iteration 4:  Residual SS =   7024938
    Calculating FGNLS estimates...
    Iteration 0:  Scaled RSS =       184
    
    FGNLS regression 
    -----------------------------------------------------------------------
           Equation |        Obs   Parms       RMSE      R-sq     Constant
    ----------------+------------------------------------------------------
     1      c_fsinc |         92       3    276.322    0.3864           a0
     2    c_sizeret |         92       4     2.0462    0.1933          a0s
    -----------------------------------------------------------------------
    
                                      (Std. Err. adjusted for 17 clusters in time)
    ------------------------------------------------------------------------------
                 |               Robust
                 |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             /a0 |   78.64377   24.02281     3.27   0.001     31.55993    125.7276
             /a1 |   189.3139   258.8931     0.73   0.465    -318.1072    696.7351
             /a2 |   .4151331   .0886469     4.68   0.000     .2413882    .5888779
          /beta1 |   .0035631   .0007052     5.05   0.000     .0021808    .0049453
            /a0s |  -697.3602    179.949    -3.88   0.000    -1050.054   -344.6668
            /a1s |   525.3674   516.2234     1.02   0.309    -486.4119    1537.147
            /a2s |   .4229619   .0851716     4.97   0.000     .2560286    .5898952
    ------------------------------------------------------------------------------
    
    .
    Your first equation is a linear regression. When I tried to execute only the first equation by -nlsur-, it failed with the error message you reported. So I executed it by -regress-, then I saved the estimation sample that regress uses, and then I tried again -nlsur-. This way -nlsur- worked.

    Comment


    • #3
      Originally posted by Joro Kolev View Post
      This is something new for me as well, but apparently -nlsur- cannot handle missing values. So you need to manually take care of the missing values.

      This is what I did:

      Code:
      . qui reg c_fsinc c_stacc c_stocf
      
      . keep if e(sample)
      (8 observations deleted)
      
      . nlsur (c_fsinc = {a0} + {a1}*c_stacc + {a2}*c_stocf)(c_sizeret = {beta1}*(c_fsinc -{a0s}-{a1s}*c_st
      > acc - {a2s}*c_stocf)), vce(cluster time)
      (obs = 92)
      
      Calculating NLS estimates...
      Iteration 0: Residual SS = 7025416
      Iteration 1: Residual SS = 7024966
      Iteration 2: Residual SS = 7024938
      Iteration 3: Residual SS = 7024938
      Iteration 4: Residual SS = 7024938
      Calculating FGNLS estimates...
      Iteration 0: Scaled RSS = 184
      
      FGNLS regression
      -----------------------------------------------------------------------
      Equation | Obs Parms RMSE R-sq Constant
      ----------------+------------------------------------------------------
      1 c_fsinc | 92 3 276.322 0.3864 a0
      2 c_sizeret | 92 4 2.0462 0.1933 a0s
      -----------------------------------------------------------------------
      
      (Std. Err. adjusted for 17 clusters in time)
      ------------------------------------------------------------------------------
      | Robust
      | Coef. Std. Err. z P>|z| [95% Conf. Interval]
      -------------+----------------------------------------------------------------
      /a0 | 78.64377 24.02281 3.27 0.001 31.55993 125.7276
      /a1 | 189.3139 258.8931 0.73 0.465 -318.1072 696.7351
      /a2 | .4151331 .0886469 4.68 0.000 .2413882 .5888779
      /beta1 | .0035631 .0007052 5.05 0.000 .0021808 .0049453
      /a0s | -697.3602 179.949 -3.88 0.000 -1050.054 -344.6668
      /a1s | 525.3674 516.2234 1.02 0.309 -486.4119 1537.147
      /a2s | .4229619 .0851716 4.97 0.000 .2560286 .5898952
      ------------------------------------------------------------------------------
      
      .
      Your first equation is a linear regression. When I tried to execute only the first equation by -nlsur-, it failed with the error message you reported. So I executed it by -regress-, then I saved the estimation sample that regress uses, and then I tried again -nlsur-. This way -nlsur- worked.
      Joro Kolev : So there is nothing to do with the initial values. It seems I cannot be careless about those missing values. Thank you very much for your help. Have a great Friday!

      Comment

      Working...
      X