Announcement

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

  • Extracting beta coefficient series from nonlinear regression

    In Stata 13

    when trying to get the series by gen b1series=_b[/b1]*(/b1) it gives an error message /b1 invalid name



  • #2
    Did you mean to write
    Code:
    generate double b1series = _b[/b1] * _b[/b1]

    Comment


    • #3
      Thank you Joseph;
      ​I simply want to generate the beta coef series for each independent variable to be used as a new variable in my new regressions.
      say for example reg y x here how to extract the coff for x: series and not scalar..... what is the function for that . please advice,

      Comment


      • #4
        If the original question was not understood by Joseph Coveney, then you need to give a better explanation than in #1.

        From an example such as

        Code:
        reg y x
        I don't think anyone will be able to see why you insist that you want a series (do you just mean set?) of coefficients.

        Consider this regression with several predictors which you can run yourself.

        Code:
        . webuse grunfeld
        
        . xtset company year
               panel variable:  company (strongly balanced)
                time variable:  year, 1935 to 1954
                        delta:  1 year
        
        . tsegen invest10 = rowmean(L(1/10).invest)
        (10 missing values generated)
        
        . edit
        - preserve
        
        . sysuse auto
        no; data in memory would be lost
        r(4);
        
        . sysuse auto, clear
        (1978 Automobile Data)
        
        . reg mpg weight displ gear
        
              Source |       SS       df       MS              Number of obs =      74
        -------------+------------------------------           F(  3,    70) =   44.05
               Model |  1597.38038     3  532.460128           Prob > F      =  0.0000
            Residual |  846.079075    70  12.0868439           R-squared     =  0.6537
        -------------+------------------------------           Adj R-squared =  0.6389
               Total |  2443.45946    73  33.4720474           Root MSE      =  3.4766
        
        ------------------------------------------------------------------------------
                 mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
              weight |  -.0065338   .0011761    -5.56   0.000    -.0088794   -.0041882
        displacement |    .007686   .0115781     0.66   0.509    -.0154058    .0307778
          gear_ratio |   .6452576   1.598012     0.40   0.688    -2.541877    3.832392
               _cons |   37.56411   6.564394     5.72   0.000     24.47184    50.65638
        ------------------------------------------------------------------------------
        
        . eret li
        
        scalars:
                          e(N) =  74
                       e(df_m) =  3
                       e(df_r) =  70
                          e(F) =  44.05286704443726
                         e(r2) =  .6537372161878035
                       e(rmse) =  3.476613858678086
                        e(mss) =  1597.380384894782
                        e(rss) =  846.0790745646774
                       e(r2_a) =  .6388973825958522
                         e(ll) =  -195.1537174962535
                       e(ll_0) =  -234.3943376482347
        
        macros:
                    e(cmdline) : "regress mpg weight displ gear"
                      e(title) : "Linear regression"
                        e(vce) : "ols"
                     e(depvar) : "mpg"
                        e(cmd) : "regress"
                 e(properties) : "b V"
                    e(predict) : "regres_p"
                      e(model) : "ols"
                  e(estat_cmd) : "regress_estat"
        
        matrices:
                          e(b) :  1 x 4
                          e(V) :  4 x 4
        
        functions:
                     e(sample)  
        
        . mat b = e(b)
        
        . mat li b
        
        b[1,4]
                  weight  displacement    gear_ratio         _cons
        y1    -.00653382       .007686     .64525763     37.564106
        You can extract coefficients to a vector in that way.

        Comment


        • #5
          Thank you Nick:

          this is my research in finance, ok I will explain more in steps :

          1- I have to regress the stock-bond dynamic correlation series (DV) on a the investor sentiment index variable (IV) : reg DV IV


          2- then I have to generate the beta coefficient series (let us give it a name bsent) for the IV from stage 1.

          3- Regress the stock-bond dynamic correlation (DV) on a macroeconomic news (IV) interacted with dummy variable in a non-linear regression:


          nl(DV={b0}+(dummy)*({b1}*IV)+ (1-dummy)*({b2}*IV)),vce (hac nw 8)
          4- I have again to generate the beta coefficient series for b1 and b2
          5- regress b1 and b2 from step 4 on beta coefficient series from 2, that is:

          reg b1 bsent

          reg b2 bsent

          I have 1540 obs, then the number of obs in each beta coefficient series must be 1540.
          My question again, how to extract the beta coefficient.


          hope it is clear now.
          Could you please advice,

          Comment


          • #6
            Sorry, but I can't get past your #1 and #2 where I can see only one regression with one predictor and thus one beta coefficient. Also, I have pointed out how to save coefficients and you have not explained at all why that is not what you want.

            Comment


            • #7
              There's something missing in your logic, here.

              You can easily create two variables representing the regression coefficients from the (linear) model that you fit with nl, just in the manner I showed, that is,
              Code:
              generate double b1 = _b[/b1]
              generate double b2 = _b[/b2]
              and in the analogous manner for regress:
              Code:
              generate double bsent = _b[investor_sentiment_index]
              But, based upon what you show, these three variables will all be constant, and so your Step 5 doesn't make any sense. regress in each instance there will give you only an intercept coefficient, _cons. The constant-valued predictor, bsent, will have been dropped by regress because it is collinear with the intercept. The intercept in each fitted model will be just the (constant) value of b1 or b2, and neither intercept coefficient will have any standard error, because there isn't any variation anywhere.

              Comment


              • #8
                Dear all;
                ​Please see equations 4, 6 & 7 in the paper attached. I am using his idea. I don't want them constant!? and this is what I am asking about, in the paper attached and other papers, they generated coeffcoeint SERIES and regressed on the new variable. in the paper attached they generated beta coefficient series from equation 4 and regress on beta coefficient series generated from equation 6 and the final equation is equation 7.. I cannot explain more. Can anybody advice? if no, then thank you.
                Attached Files
                Last edited by abdelrazzaq alrababaa; 31 Dec 2015, 06:25.

                Comment


                • #9
                  my simple assumption is that the effect of sentiment on stock-bond correlation affect the stock-bond correlation reaction to the macroeconomic data

                  Comment


                  • #10
                    ?

                    Comment


                    • #11
                      can anybody advice please

                      Comment


                      • #12
                        Unfortunately I don't think this thread will converge.

                        Personally, I got lost a while back, but I won't (try to) read a long and difficult-looking paper on a subject of no interest to me just to understand your question. I don't work in finance, so I don't even understand the verbal summary in #9.

                        That doesn't rule out other people closer to your field becoming interested, but it hasn't happened.

                        Joseph and I tried to make suggestions of various kinds, but I don't see that you explained anywhere precisely why those suggestions were wrong or irrelevant.

                        There is unlikely to be any progress unless you can refocus the thread on the precise Stata question you have, based on data we can use and code we can copy. As always, the FAQ gives advice on how to ask questions.


                        Comment


                        • #13
                          Dear Nick;
                          ​thank you for your comment.. to be honest, I am so confused and I cannot understand how I can explain my question more...

                          Is there a way in Stata to extract the beta coefficient as a series and not as scalar single value. when we say the beta coefficient is equal to 0.002 then it does not mean it is 0.002 for each single observation in the DV and IV variable, there should be values for each observation and the final scalar value is 0.002, how to access that series
                          here is a similar questions you were aware of in the past,
                          "how to access coefficients for each observation in panel data with fixed effects"

                          my question is the same and I don't know what is wrong here. It is an additional robustness check to be used in my paper and I spent the last two weeks googling for the answer and reading the Stata user's guide and I cannot find the answer, should not be that hard.

                          also the link below for similar question .







                          Comment


                          • #14
                            It's clear that you are frustrated, but you are not following any of the advice given here. I asked for data we can use and code we can copy. I see none here. Nor are you explaining why (e.g.) Joseph's suggestion is wrong. Similarly, if some past thread (no URL there) is asking the same question, then why is the answer there not what you want?

                            I suggest that you find a Stata user at your workplace who can talk you through this.
                            Last edited by Nick Cox; 01 Jan 2016, 17:40.

                            Comment


                            • #15
                              Thank you Nick... I am not saying Joseph's suggestion is wrong. Many thanks for your help. I tried to explain as mush as I can, I cannot post my any data (or even sample of data) I bought as there is an agreement with the data provider not to post or distribute. However, assume that you have any two series and one (0,1) dummy series to be used in the interaction term in my NL regression , then how to do extract the beta coff. after employing this data.

                              ​What you and Joseph suggested I already found in some Stata help files online. My question was fairly simply, how to generate the beta coefficient series. Thank you again, I am going to delete my post and look for the answer myself or using some other websites.

                              Comment

                              Working...
                              X