Announcement

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

  • time series independent and panel data dependent

    Hi Statalisters
    I have three independent variables (Rm-Rf, SMB and HML) Fama-French variables in time series form (each 251 time points) and returns variables in unbalanced panel data form (1500 firms and 251 time points)
    In one step, How can I run 1500 regressions (regression for each firm)?
    Since I need coefficients for each firm?



    any help will be greatly appreaciated
    Last edited by Muhammed Shaker; 30 Apr 2016, 14:16.

  • #2
    Look at the command statsby. I think this is what you want.
    Stata/MP 14.1 (64-bit x86-64)
    Revision 19 May 2016
    Win 8.1

    Comment


    • #3
      Many thanks
      Will statsby help generate residuals for each firm after estimation?

      Comment


      • #4
        statsby will store coefficients, standard errors, etc in a dataset. If you want to generate the residuals for each firm, you will have to run a loop to run the regressions and then generate the residuals for each firm. While it will take longer, it is probably easier to do it in two steps:

        Code:
        statsby firm: reg ...
        
        gen all_residuals
        levelsof firm, local(FIRM)
        foreach f of local FIRM {
        reg ... if firm==`f'
        predict res, res
        replace all_residuals if firm==`f'
        drop res
        }

        Stata/MP 14.1 (64-bit x86-64)
        Revision 19 May 2016
        Win 8.1

        Comment


        • #5
          it is not working this code. it generates the first panel only. please take into your account that the number of firms is 2000 while I have only 200 time points
          any help?

          Comment


          • #6
            Saying that something does not work is not helpful. If I tell you that my computer is not working, what advice can you possibly give me? The possible sources of problems are endless.

            Also, what does "this code" refer to? What Carole showed you in #4 is not code: it is a template that you needed to complete with details to turn it into code that you could actually run. The ... places require you to list the actual variables you want to use in your regressions. And firm may need to be replaced by the name of whatever variable in your data set identifies firms (if that variable is not called firm).

            So, show the exact code you actually ran, and show the complete output (including any error messages or warnings) that Stata generated in response. Every detail is important, so to assure complete accuracy, you should do this by copying directly from the Results window or Stata log file to your clipboard and then pasting into a code block (See FAQ #12) in this Forum. Don't edit it in any way. (And do not retype it: use copy/paste on your computer.)

            Comment


            • #7
              I ran statsby command as follows:
              statsby by(panelid) saving(mohamed, replace):arch returns mktrf SMB HML , earch(1) egarch(1)
              The result was one dot and 2077 (number of firms) red X.
              I guess STATA ran the the three independent variables (mkmf, smb and hml) using the first panel data only
              I want to tell STATA run the same independent variables for each panel
              in other words, i have 200 time series observation for each of the independents and 170,000 dependent variable observation in the form of panel data.
              kindly do not forget I need to compute residuals for each panel (company)
              Attached Files
              Last edited by Muhammed Shaker; 05 May 2016, 13:28.

              Comment

              Working...
              X