Announcement

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

  • Testing nonlinear restrictions after estimating a system of equations

    Dear all

    I have a system of five equations that I want to estimate and then test for nonlinear restrictions.
    I will give an example here for two equations of the system only and a restriction that I want to test to make it simplified at this stage.

    HTML Code:
    nlsur(f_profit={A0}+{A1}*base+{A2}*cashf+{A3}*growth)(f_return={Beta}*(f_profit-{Ac0}-{Ac1}*base-{Ac2}*cashf-{Ac3}*growth)), ifgnls vce(robust)variables(base cashf growth f_profit f_return)
    
    testnl [A1]+[A3]/0.3 =[Ac1]/[Ac2]*0.12
    nlsur runs smoothly and provides results. I can not figure how to test the restriction using testnl or any other relevant programme. The code for testnl produces an error message.
    Can any one help me to test this restriction after estimating the system>

    Thanks
    Mike

  • #2
    Paste the error message that -testnl- produces.

    Comment


    • #3
      Hi
      The problem is not in the error message itself. In fact, I am not sure what the beat way is to test such nonlinear reatriction after nlsur?! I gave only an example here.
      I hope someone can help in this please.
      Thanks
      Mike

      Comment


      • #4
        The best way to test nonlinear restrictions after any command, including -nlsur- is -testnl-. Like I have done below:

        Code:
        . webuse petridish, clear
        
        . nlsur (p1 = {b1}*{b2}^t) (p2 = {g1}*{g2}^t), nolog
        (obs = 25)
        Calculating NLS estimates...
        Calculating FGNLS estimates...
        
        FGNLS regression 
        -----------------------------------------------------------------------
               Equation |        Obs   Parms       RMSE      R-sq     Constant
        ----------------+------------------------------------------------------
         1           p1 |         25       2   .4337019    0.9734*      (none)
         2           p2 |         25       2   .3783479    0.9776*      (none)
        -----------------------------------------------------------------------
        * Uncentered R-sq
        
        ------------------------------------------------------------------------------
                     |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
                 /b1 |   .3926631    .064203     6.12   0.000     .2668275    .5184987
                 /b2 |   1.119593   .0088999   125.80   0.000     1.102149    1.137036
                 /g1 |   .5090441   .0669495     7.60   0.000     .3778256    .6402626
                 /g2 |   1.102315   .0072183   152.71   0.000     1.088167    1.116463
        ------------------------------------------------------------------------------
        
        . testnl _b[/b1]/_b[/b2]=_b[/g1]
        
          (1)  _b[/b1]/_b[/b2] = _b[/g1]
        
                       chi2(1) =        4.31
                   Prob > chi2 =        0.0379

        Comment


        • #5
          Thanks a lot for your help.

          Just to be sure you are testing if b1/b2 = g1
          why do you need "/" before each coefficient ?

          also I have more complicated tests. For example, in your exercise how would you test:

          b1 divided by (b2/g2) =( g1+0.12) multiplied by (b1+b2) and all divided by (g2- 0.14)

          Comment


          • #6
            Yes, this is what I am testing, Ho: b1/b2 = g1, and arbitrary nonlinear hypothesis.

            When Stata calls a coefficient mpg, I refer to it as _b[mpg]. When Stata calls a coefficient /b, I refer to it as _b[/b].

            You just write out the hypothesis as you would have written it out mathematically on a sheet of paper, referring to coefficients using the rule above:

            Code:
            . testnl _b[/b1]/(_b[/b2]/_b[/g2]) = ( _b[/g1]+0.12)*(_b[/b1]+_b[/b2])/ (_b[/g2]- 0.14)
            
              (1)  _b[/b1]/(_b[/b2]/_b[/g2]) = ( _b[/g1]+0.12)*(_b[/b1]+_b[/b2])/ (_b[/g2]- 0.14)
            
                           chi2(1) =       29.81
                       Prob > chi2 =        0.0000

            Comment


            • #7
              You can also easily convince yourself that "you need "/" before each coefficient ", because if you try to do it without it, it is not working:

              Code:
              . testnl _b[b1]/_b[b2] = _b[g1]
              
                (1)  _b[b1]/_b[b2] = _b[g1]
              [b1] not found
              r(111);
              
              . testnl _b[/b1]/_b[/b2]=_b[/g1]
              
                (1)  _b[/b1]/_b[/b2] = _b[/g1]
              
                             chi2(1) =        4.31
                         Prob > chi2 =        0.0379

              Comment


              • #8
                Thanks a lot. I wrote the code for my equations based on your advice and it seems to be working.

                However,
                1- The equations are meant to be estimated with firm and year fixed effects. Is there any way that I can include the firm and year dummies?

                2- I also supposed to cluster by firm and year but it appears that there is only one dimension cluster via vce(cluster). Is there any way to do that?

                Thanks

                Comment


                • #9
                  Including fixed effects should be easy. Just directly include them in -nlsur- with factor notation -i.year i.firm-.

                  Two dimensional clustering as you say is not in -nlsur-. To my knowledge in the whole Stata universe there is no pre-programmed routine that can do two dimensional clustering for nonlinear estimator and/or nonlinear hypothesis tests.

                  Some years ago I studied in detail the papers on two dimensional clustering Thompson, S.B., 2011. Simple formulas for standard errors that cluster by both firm and time. Journal of financial Economics, 99(1), pp.1-10; and Cameron, A.C., Gelbach, J.B. and Miller, D.L., 2011. Robust inference with multiway clustering. Journal of Business & Economic Statistics, 29(2), pp.238-249.

                  There is a relatively easy way how to manually calculate the two-way clustered variance. If we call the variance clustered in firm dimension V(f), the variance clustered in year dimension V(y), and the heteroskedasticity only robust variance V(0), the two dimensionally clustered variance has some very simple form of the sort V(f)+V(y)-V(0).

                  However do read the original paper before you do this. I was working on these two papers in detail before year 2011, and probably read them last time when they got published in 2011. It is not clear how much I remember from this time, so do verify everything that I am saying above for yourself before you implement it.

                  Comment


                  • #10
                    Thanks
                    Regarding the firm or year fixed effects, I tried to add them initially but I get an error message "i: operator invalid. There might be a certain way to code that but I do not know. For other variables, we did {coeff}* variable , but given that the year fixed effect will have many coefficients, I am not sure how this will be coded. When I simply added i.yr or i.firm as you suggested I got the error message above.

                    Any advice?

                    Thanks

                    Comment


                    • #11
                      It appears -nlsur- does not accept factor notation. By the way, I have been assuming that you want to enter the dummies linearly.

                      In -nlsur- you can use linear combinations, and it appears that linear combinations accept wild cards.

                      So you can try to generate the dummies manually firstly, probably easiest would be

                      tab year, gen(yr)

                      and

                      tab firm, gen(frm)

                      and then include in your -nlsur- estimation command in whichever equation you want to include them

                      nlsur (first equation stuff here) (second equation stuff here + {xb: yr* frm*})

                      This mechanically should work.

                      But whether it makes sense to include such dummies in a nonlinear model, I do not know.

                      Comment


                      • #12
                        Hi
                        I have tried to write the full code for my system and Stata keeps on issuing the error message
                        Code:
                          invalid something: unmatched open parenthesis or bracket
                        I do not think there are any open brackets but I do not really know where the error is coming from. I wrote the code as suggested, as if I am writing a mathematical equation.
                        Code:
                        nlsur (f_varA={k10}+{k11}*varA+{k12}*varB+{k13}*varC+{k14}*varD) ///
                        (f_varB={k20}+{k22}*varB) ///
                        (f_varC={k30}+{k33}*varC) ///
                        (f_varD={k40}+{k44}*varD) ///
                        (f_return={theta1}*(f_varA-{kr10}-{kr11}*varA-{kr12}*varB-{kr13}*varC-{kr14}*varD) ///
                        +{theta2}*(f_varB-{kr20}-{kr22}*varB) ///
                        +{theta3}*(f_varC-{kr30}-{kr33}*varC) ///
                        +{theta4}*(f_varD-{kr40}-{kr44}*varD) ///
                        ,fgnls vce(gnr) variables (f_varA f_varB f_varC f_varD f_returnW  varA varB varC varD)
                        I appreciate if you have any advice.

                        Thanks a lot
                        Mike

                        Comment


                        • #13
                          For reasons I do not fully understand, sometimes Stata does not accept this breaking of lines ///.

                          Try:

                          1. Put the equation on the same line, e.g.

                          Code:
                            
                           (f_return={theta1}*(f_varA-{kr10}-{kr11}*varA-{kr12}*varB-{kr13}*varC-{kr14}*varD) /// +{theta2}*(f_varB-{kr20}-{kr22}*varB) /// +{theta3}*(f_varC-{kr30}-{kr33}*varC) /// +{theta4}*(f_varD-{kr40}-{kr44}*varD) ///
                          to become

                          Code:
                           
                           (f_return={theta1}*(f_varA-{kr10}-{kr11}*varA-{kr12}*varB-{kr13}*varC-{kr14}*varD) +{theta2}*(f_varB-{kr20}-{kr22}*varB) +{theta3}*(f_varC-{kr30}-{kr33}*varC) +{theta4}*(f_varD-{kr40}-{kr44}*varD)
                          2. If 1. above does not work, see the -help delimit- and switch temporarily (or permanently ) to the ";" delimiter.

                          Comment


                          • #14
                            I tried both solutions.
                            I- I have initially tried to do that and it did not work (i.e. I get the same error message as per my previous post)
                            2- Now I tried #delimit. I get no error message but no output.

                            Do you think this model can not be estimated? or that there is something incorrect when I code the equations?

                            Any more suggestions?

                            Comment


                            • #15
                              Mike, when you do things that look like the mess of the type that you are doing--plenty of opening parentheses and curly brackets, plenty of closing ones--you are better off using some text editor that can highlight the syntax and can signal whether you are closing appropriately the parentheses you are opening.

                              I for example when I have the type of the mess you have, copy and paste my equation in WinEdt and then I go through to check whether I am opening and closing the parentheses properly (and this is not the best idea around, I am dealing with it in a very primitive way).

                              So, now I did just that, and WinEdt tells me that you have not closed properly the parenthesis of

                              Code:
                              (f_return={theta1}*(f_varA-{kr10}-{kr11}*varA-{kr12}*varB-{kr13}*varC-{kr14}*varD) ///
                              +{theta2}*(f_varB-{kr20}-{kr22}*varB) ///
                              +{theta3}*(f_varC-{kr30}-{kr33}*varC) ///
                              +{theta4}*(f_varD-{kr40}-{kr44}*varD) ///
                              you need one more closing parenthesis here, like this:

                              Code:
                              (f_return={theta1}*(f_varA-{kr10}-{kr11}*varA-{kr12}*varB-{kr13}*varC-{kr14}*varD) ///
                              +{theta2}*(f_varB-{kr20}-{kr22}*varB) ///
                              +{theta3}*(f_varC-{kr30}-{kr33}*varC) ///
                              +{theta4}*(f_varD-{kr40}-{kr44}*varD)         )       ///
                              I left you a couple of empty spaces before and after so that you can see where is the missing closing parenthesis. Fix this, and try again.

                              Comment

                              Working...
                              X