Announcement

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

  • Using the operator "exp" in a regression

    Dear all,
    I use Stata 14.1 . I ran ivreg28 using the following command (which used to work on my Stata 13 version)
    Code:
    loc x "age  education Germany US "
    loc z "age  education Germany US  motivation love important male"
    ivreg28  abroad exp(age) exp(education) exp(Germany) exp(US)  (Tie contact skype facebook email=`z')
    For some reason I receive:
    exp: operator invalid
    I'm not sure what is the problem, any advice?
    Thanks,
    Anat

  • #2
    I don't think I have ever encountered such syntax. I don't think operators are allowed in regressions. if you want to regress y on e^x rather than on x, you should:
    gen exp_x = exp(x)
    and then reg y exp_x .

    the same goes for other operators, for example reg y x+z is not allowed. and should instead use:
    gen x_plus_z = x+z
    reg y x_plus_z

    code example:
    Code:
    . sysuse auto
    (1978 Automobile Data)
    
    . reg price exp(mpg)
    variable exp not found
    r(111);
    
    . gen exp_mpg = exp(mpg)
    
    . reg price exp_mpg
    
          Source |       SS           df       MS      Number of obs   =        74
    -------------+----------------------------------   F(1, 72)        =      0.07
           Model |  616560.282         1  616560.282   Prob > F        =    0.7921
        Residual |   634448836        72  8811789.39   R-squared       =    0.0010
    -------------+----------------------------------   Adj R-squared   =   -0.0129
           Total |   635065396        73  8699525.97   Root MSE        =    2968.5
    
    ------------------------------------------------------------------------------
           price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
         exp_mpg |  -1.24e-15   4.67e-15    -0.26   0.792    -1.05e-14    8.08e-15
           _cons |   6176.005   347.4611    17.77   0.000     5483.354    6868.656
    ------------------------------------------------------------------------------
    
    . reg price weight+mpg
    + invalid name
    r(198);
    
    . gen weight_plus_mpg = weight + mpg
    
    . reg price weight_plus_mpg
    
          Source |       SS           df       MS      Number of obs   =        74
    -------------+----------------------------------   F(1, 72)        =     29.38
           Model |   184056991         1   184056991   Prob > F        =    0.0000
        Residual |   451008405        72  6264005.63   R-squared       =    0.2898
    -------------+----------------------------------   Adj R-squared   =    0.2800
           Total |   635065396        73  8699525.97   Root MSE        =    2502.8
    
    ---------------------------------------------------------------------------------
              price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    ----------------+----------------------------------------------------------------
    weight_plus_mpg |   2.055411   .3791828     5.42   0.000     1.299524    2.811298
              _cons |  -84.74845   1189.144    -0.07   0.943    -2455.264    2285.767
    ---------------------------------------------------------------------------------
    also, something regarding your estimation - If I understand it correctly several of your excluded instruments (Z) are also included instruments, just in exponeanted form. this means that identification arises directly from the functional form of the variables.

    Comment


    • #3
      Little unsure as to what you are trying to do. exp() would be for exponentiating vars, which you can use in calculating a new variable, but not in a regression. If instead you are trying to include different levels of each fo those variable,s have a look at factor variables in http://www.stata.com/manuals13/u25.pdf

      Comment


      • #4
        People have often asked for such syntax -- it was mentioned again at the Chicago Conference at the end of July -- but it has never been supported generally in Stata. I have to guess you are remembering use of some other software. If you can show logs from Stata 13 where this worked, then please do so.

        Comment


        • #5
          Thanks all!!! (sorry for late responding, was under the weather ). Jorrit Gosens yes the exp() was for exponentiation vars. Nick Cox I'll try to recreate the results in Stata 13.0 (Its not available on my laptop). However, the same logic should work for the operator ln (natural logarithm of vars.) , right? yet the following code with the ln operator (in bold) is working perfectly on my Stata 14.1. Not sure what is the difference..
          Code:
          #delimit;
          gmm (eq1: ln( marketshare)- {B0}-{xb: agri_activity extreme_activity agri_sale food_sales guided_act 
          access  uppergalilee}+{alpha}*(ln(total_price))-{sigma}*(ln(region_ms)))
          (eq2: ln(total_price)-{C0}-{xc:extreme_activity agri_activity agri_sale food_sales guided_act 
          investment_scaled }+(ln(({alpha}*(1-{sigma}*region_ms-(1-{sigma})*marketshare))/ ({alpha}*(1+{sigma}*region_ms-(1-{sigma})*marketshare))+1-{sigma})))
          , instruments(eq1: X) instruments(eq2: Z) twostep winit(unadj,indep) from( alpha 0.5 sigma 0.78);

          Comment


          • #6
            A key word in my post #4 was generally. gmm and also nl are commands with very specific syntax. The detail is whether ivreg28 supported syntax like this, ever, which was what you claimed in #1.

            Comment


            • #7
              I hadnt ever encountered the use of such operators with any command. Gmm is very specific in that it would need some operators to write out equations, but like Nick says, not part of the core Stata options.
              Biggest reason I wasn't sure what you wanted to do was that i'd expect 'US' and 'Germany' to be dummies, and I couldnt really see a point in exponentiating those.

              Comment


              • #8
                Thanks Jorrit, you defeneitly have a point, ('US' and "Germany" are not dummy vars. anyway)...I guess there is no point trying to repeat the ivreg28 code which I probably mistakenly remembered it worked.. Thank again

                Comment

                Working...
                X