Announcement

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

  • Lopping and storing beta coeffecients

    Hi, so I am going to perform a fama macbeth two path regression.

    The regressions that I am going to perform looks like this:


    Book leverage = x1 x2 x3 x4 x5

    I am running this regression on 900 firms.

    But as the second step is to regress each firmyear observation on the beta coeefecients, I would need to save the 5 beta values above in 5 different variables (b1, b2, b3, b4, b5).

    The second regression will then look something like this:


    Book leverage = b1 b2 b3 b4 b5

    In this case I will receive a new beta value for regressing upon each beta value, we can call these values gamma instead (g1, g2, g3, g4, g5).

    I then need to save these five gammas to be able to perform further analysis upon them.


    I have done the following so far:

    levelsof id, local(tempid) //Saving the unique id's in a local file to be used as identifier for the looped regressions

    foreach i in `tempid' {
    regress b_lev x1 x x3 x4 x5
    }

    What I need help with is to find out how I am able to store each beta value in new variables. And please explain your code.

    Thank you in Advance

    Best regards, Morten



  • #2
    Hi Morten,

    The statsby command should do what you need. In the first stage, something like this (untested) code:

    Code:
    statsby, by(`tempid') regress b_lev  x1 x2 x3 x4 x5
    See the help file for details and options.

    Best,
    Devra
    Devra Golbe
    Professor Emerita, Dept. of Economics
    Hunter College, CUNY

    Comment


    • #3
      Hi Devra, this does not solve my issue.

      I do not understand, why this has to be so complicated.

      First of all, I do not understand what the "statsby" command gives me?

      Second of all, why the option "by(`tempid') when I have already told the loop that I am running it by the tempgvkey

      Thirdly, I get a "no, data in memory would be lost" when trying to run the code.



      Why is it so complicated? Is there really no direct code that tells stata to: CREATE A VARIABLE AND STORE IN THIS VARIABLE THE _b each time.

      Best, Morten

      Comment


      • #4
        You'll increase your chances of a useful answer by following the FAQ on asking questions - provide Stata code in code delimiters, readable Stata output, and sample data using dataex. If you had done that, Devra might have been able to more fully answer your question.

        You won't get far whining about the help someone tries to provide you. Everyone on this list is helping out of the goodness of their hearts - you should be appreciative not arrogant.

        It seems complicated because you need to (i) tell Stata what subset of the data you want to run the estimation on, (2) save the parameters, and (3) put the parameters in the right observations.

        You can't get much simpler than statsby.

        Devra's code replaces the data in memory with the b's - see the documentation for statsby - that is why Stata warned you. If you read the documentation, you'll see that you can save the parameters to a file and then reload them if you need them. The by tempid in statsby replaces your loop.

        Alternatively, from your code you could do something like:

        g bx1=.
        g bx2=.

        foreach i in `tempid' {
        regress b_lev x1 x2 if id==`i'
        replace bx1=_b[x1] if id==`i'
        replace bx2=_b[x2] if id==`i'
        }



        Comment


        • #5
          Morten,

          Have you read the helpfile and/or the manual entry for statsby? Stata's manuals are really excellent. Here's what the helpfile says:


          statsby collects statistics from command across a by list. Typing

          . statsby exp_list , by(varname): command

          executes command for each group identified by varname, building a dataset
          of the associated values from the expressions in exp_list. The resulting
          dataset replaces the current dataset, unless the saving() option is
          supplied.
          If I understand your problem correctly, statsby gives you exactly what you need, and in a very simple way. You don't need to build your own loop.

          I have often found that the best way to understand what a command does is to try out the example code. Here's the first example in the helpfile, adding a list command so you see exactly what you get:

          Code:
          sysuse auto
           statsby, by(foreign): regress mpg gear turn
          list

          Once you understand the examples, I suggest you extract a small sample of your data (say 10-25 firms) on which to test the code you need for your specific problem. That will save you a lot of time and frustration.

          Best,
          Devra
          Devra Golbe
          Professor Emerita, Dept. of Economics
          Hunter College, CUNY

          Comment


          • #6
            Thank you both of you. I was definetily not being non appreciative. Just frustrated with my work. I am used to using Eviews, which just seems much simpler when it comes to loops.

            Anyway, I get the warning of "no, data in memory would be lost" and I do not know how to get around it. Any help?

            Best,
            Morten

            Comment


            • #7
              And now I am frustrated, too. If you read Phil's answer carefully, you will see that he's already answered this question. And please: read the FAQ.

              Devra
              Devra Golbe
              Professor Emerita, Dept. of Economics
              Hunter College, CUNY

              Comment


              • #8
                Hi Devra. No, the program stops running when it gives me the warning. I am not able to access the beta values because the program do not run the statsby code. This is what I am frustrated about. And no, it does not help if I save the file

                Code:
                levelsof gvkey, local(tempgvkey)
                
                statsby _b, by(`tempgvkey'): regress b_lev L1.mb L1.profitability L1.tangibility L1.size
                However, running this code gives me the following error:

                "no, data in memory would be lost"

                Running the autosys example that you gave me works without giving me the warning. That is why I am confused.

                //Morten

                Comment


                • #9
                  Problem solved, writing the following:


                  Code:
                  statsby, by(id) saving(estimation): regress b_lev L1.mb L1. profitability L1.tangibility L1.size
                  I did not even need to specify the unique values of the id.


                  Thank you.

                  // Morten

                  Comment

                  Working...
                  X