Announcement

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

  • Generating a time series of Beta

    Dear Stata community,

    For my Master Thesis I need to generate a time series of beta's for different dummies. I run the following regression: reg return i.industry i.country. I have daily data over the period 1/1/1999 till 1/1/2018, now I want the betas for each month so I can see how the betas evolve over time.

    So far, the only option I figured was to run all the regressions for every month and copy the different betas by hand.

    Hopefully one of you can help me saving this time and creating a nice time series of betas

    Lots of thanks in advance!

    Kind regards,

    Ruben Jakobs

  • #2
    You can use rangestat (SSC) for this. Search the forum for mentions. You'll need a monthly date variable if you don't have one.

    Smileys, thanks in advance and kind regards are all welcome, but the nicest thing you can do is give us a real data example!

    Comment


    • #3
      Thanks Nick,

      Below is an example of my data. As said I run "reg return i.country i.industry" now I would like Stata to save the betas calculated for each dummy for each time t as new variables.

      date _j price country return industry marketcap country1 cdum1 cdum2 cdum3 idum1 idum2 idum3 idum4
      1/8/1999 1 3.046 Italy 0.20 3 174294 Italy 1 0 0 0 0 0 1 0
      1/8/1999 2 4289.383 Ireland 0.11 2 9798870 Ireland 1 0 0 0 0 0 0 0
      1/8/1999 3 .171 Belgium 0.00 4 38255 Belgium 1 0 0 1 0 0 0 0
      1/8/1999 4 186 Germany 0.03 1 10066175 Germany 1 0 0 0 0 0 0 0

      Comment


      • #4
        Thinking about it more, I have changed my mind. Guessing somewhat, as date above could be various things (please use dataex in future), something like this would be a smidgen more direct.

        Code:
        gen mdate = mofd(date) 
        
        statsby , by(mdate) :  reg return i.industry i.country

        Comment


        • #5
          I still walk into two problems.

          #1. I can't keep the original data in memory while executing the code is there a way in Stata where I can keep the data in the same workfile?

          #2. I tried to use the "noconstant" option but that doesn't work when I use the code.

          Can I overcome these problems?

          Comment


          • #6
            #1. You can merge back with the original. Or use rangestat. Or there are other solutions.

            #2. Please see FAQ Advice #12 on why "doesn't work" is no help as a problem report.

            This works for me. What you are doing differently?

            Code:
            . sysuse auto, clear
            (1978 Automobile Data)
            
            . 
            . gen gpm = 1000/mpg 
            
            . 
            . regress gpm weight i.foreign, noconstant 
            
                  Source |       SS           df       MS      Number of obs   =        74
            -------------+----------------------------------   F(2, 72)        =   2477.57
                   Model |  195545.778         2  97772.8892   Prob > F        =    0.0000
                Residual |  2841.34611        72  39.4631405   R-squared       =    0.9857
            -------------+----------------------------------   Adj R-squared   =    0.9853
                   Total |  198387.125        74  2680.90709   Root MSE        =     6.282
            
            ------------------------------------------------------------------------------
                     gpm |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
            -------------+----------------------------------------------------------------
                  weight |    .016043   .0002563    62.60   0.000     .0155321    .0165539
                         |
                 foreign |
                Foreign  |   5.974317   1.464955     4.08   0.000     3.053983     8.89465
            ------------------------------------------------------------------------------
            
            . 
            . statsby, by(foreign) clear : regress gpm weight , noconstant 
            (running regress on estimation sample)
            
                  command:  regress gpm weight, noconstant
                       by:  foreign
            
            Statsby groups
            ----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5 
            ..
            
            . 
            end of do-file
            
            . list
            
                 +---------------------+
                 |  foreign   _b_wei~t |
                 |---------------------|
              1. | Domestic   .0160064 |
              2. |  Foreign   .0187188 |
                 +---------------------+

            Comment


            • #7
              I guess my problem is that I have two different sets of dummies. ibn.industry and ibn.country, when I use the noconstant option I still lose one country dummy.

              I constructed a variable which I want to serve as a base, so that every variable in the regression is relative to this, I called it eumean.

              Then I tried using fvset base default mean, but that didnt work.

              Code:
              fvset base default eumean

              . reg return ibn.industry ibn.country1, noconstant
              note: 3.country1 omitted because of collinearity

              Source | SS df MS Number of obs = 210,771
              -------------+---------------------------------- F(12, 210759) = 18.16
              Model | .979611941 12 .081634328 Prob > F = 0.0000
              Residual | 947.287827 210,759 .004494649 R-squared = 0.0010
              -------------+---------------------------------- Adj R-squared = 0.0010
              Total | 948.267439 210,771 .004499041 Root MSE = .06704

              ------------------------------------------------------------------------------
              return | Coef. Std. Err. t P>|t| [95% Conf. Interval]
              -------------+----------------------------------------------------------------
              industry |
              0 | -.0010359 .0008693 -1.19 0.233 -.0027397 .000668
              1 | -.003176 .0006689 -4.75 0.000 -.004487 -.0018651
              2 | -.0024562 .0003746 -6.56 0.000 -.0031903 -.001722
              3 | -.0023428 .0004302 -5.45 0.000 -.0031859 -.0014996
              4 | -.0048681 .0008432 -5.77 0.000 -.0065208 -.0032153
              5 | -.0008557 .0004587 -1.87 0.062 -.0017548 .0000435
              6 | -.001479 .0010058 -1.47 0.141 -.0034504 .0004924
              7 | -.0030069 .0007655 -3.93 0.000 -.0045074 -.0015065
              8 | -.0016427 .0003543 -4.64 0.000 -.0023371 -.0009483
              9 | -.0041895 .0005799 -7.22 0.000 -.0053261 -.0030529
              |
              country1 |
              Ireland | .0048569 .0004964 9.79 0.000 .003884 .0058297
              Italy | .00331 .000331 10.00 0.000 .0026612 .0039588
              Netherlands | 0 (omitted)
              ------------------------------------------------------------------------------

              Comment


              • #8
                Sorry, but I don't see anything in #7 relevant to your previous question. You have given an example where the noconstant option works, i.e. the syntax is legal and the output is correct. Omitting a predictor because of collinearity is exactly what should happen. So, how does that bear on the problems reported in #5?

                Comment


                • #9
                  In #7 you can see at the bottom that country1 dummy "Netherlands" is ommited in the regression. I would like to keep this dummy in the regression so I can interpret all dummies relative to Alpha.

                  Or an other predetermined base level.

                  Comment


                  • #10
                    See the help for regress and the allbaselevels option.

                    (I don't know what Alpha is.)

                    Comment


                    • #11
                      Thank you Nick! Unfortunately I can't get it working, also not with allbaselevels option. As shown in #7, I regress with two different sets of dummies, industry and country. And when I use the ibn. and noconstant option this only works for my industry dummies. The Netherlands is still ommitted in the regression, although I do not want this.

                      Comment


                      • #12
                        I am bailing out here, as this is just another example of "didn't work", already warned against. Sympathies, but no solutions from me. I appreciate fully that your dataset is far too large to post here but without a reproducible example I can't guess at what is going on. Someone else may have better insight.


                        EDIT: You've found a thread at https://www.statalist.org/forums/for...ummy-variables which seems to likely to imply a better answer.
                        Last edited by Nick Cox; 16 May 2018, 06:35.

                        Comment


                        • #13
                          test attach data


                          Last edited by Ruben Jakobs; 21 May 2018, 03:13.

                          Comment

                          Working...
                          X