Announcement

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

  • Estimating beta's for each id and store in a variable - panel data

    Dear Stata users,

    I have an unbalanced panel dataset with 4329 observations and about 400 variables. Time periods range from 2003 to 2010 with gaps.

    I would to run a time-series regression to estimate beta coefficients and store them in a variable for each mfiid and its time period, taking into account the panel structure (gaps). _roe is the dependent, _sp500 the independent variable. The dependent variable varies by mfiid each year and the independent variable is the same for each mfiid each year.

    Sorted by year and mfiid:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long mfiid int year float(_roe _sp500)
    100000 2007    .2913083 -.010829791
    100000 2008   .17713334   -.4216229
    100000 2009   .14123334     .201956
    100001 2004   .04955833    .0472585
    100001 2005 -.008699998  -.01277183
    100001 2006   .02328333   .08855005
    100001 2007   .21060835 -.010829791
    100001 2009  .015933335     .201956
    100001 2010  .017058332   .09580792
    100004 2008   .20683333   -.4216229
    100008 2006   -.4828166   .08855005
    100008 2007   -.4197917 -.010829791
    100008 2008  -2.9300666   -.4216229
    100008 2009    9.721633     .201956
    100012 2005       .3659  -.01277183
    100012 2006   -.4431167   .08855005
    100012 2007   1.6969082 -.010829791
    100012 2008   1.2119334   -.4216229
    100012 2009    .9820334     .201956
    100012 2010   .16185834   .09580792
    100013 2009  -.10906667     .201956
    100013 2010  -.13484167   .09580792
    100016 2005      -.0101  -.01277183
    100016 2006 .0035833344   .08855005
    100016 2007  .016408335 -.010829791
    100016 2008   .05173333   -.4216229
    100016 2009   .07153333     .201956
    100016 2010   .08925833   .09580792
    100017 2003      .17895    .2237602
    100017 2004   .16935833    .0472585
    100017 2006   .09988333   .08855005
    100020 2007  .003608331 -.010829791
    100020 2008  .010133334   -.4216229
    100020 2009   .09823333     .201956
    100020 2010  .016058333   .09580792
    100021 2005      -.0768  -.01277183
    100021 2006  -.05961667   .08855005
    100021 2007 -.017191667 -.010829791
    100021 2008  -.04696666   -.4216229
    100021 2009 -.023466665     .201956
    100021 2010 -.014741667   .09580792
    100024 2006    .9799833   .08855005
    100024 2009   .51533335     .201956
    100024 2010  .014058333   .09580792
    100026 2004   17.870058    .0472585
    100026 2005       -5.09  -.01277183
    100026 2006    9.523084   .08855005
    100026 2007  -2.4865916 -.010829791
    100026 2008   .54033333   -.4216229
    100026 2009   1.4377333     .201956
    100026 2010    .4943583   .09580792
    100027 2003   1.0200499    .2237602
    100027 2004    .8740584    .0472585
    100027 2005       .7555  -.01277183
    100027 2006   .16448334   .08855005
    100029 2006  -.16821668   .08855005
    100029 2007   .27910832 -.010829791
    100029 2008   .07793334   -.4216229
    100029 2009  .005633332     .201956
    100030 2005      -.0131  -.01277183
    100030 2006  .024183333   .08855005
    100030 2007   .02750833 -.010829791
    100030 2008   .05113334   -.4216229
    100031 2005        -.02  -.01277183
    100031 2006  -.03771666   .08855005
    100031 2007 -.033691667 -.010829791
    100031 2009   .14953333     .201956
    100031 2010   .19615833   .09580792
    100032 2004   .06425834    .0472585
    100032 2005      -.0216  -.01277183
    100032 2008   .17953333   -.4216229
    100032 2010   .17735833   .09580792
    100033 2005    .9403999  -.01277183
    100033 2006    .7986833   .08855005
    100033 2007   .07110833 -.010829791
    100033 2008   .05233334   -.4216229
    100033 2009   .03813333     .201956
    100033 2010   .23085834   .09580792
    100036 2003     1.58285    .2237602
    100036 2004    16.50846    .0472585
    100036 2005       .0053  -.01277183
    100036 2006    .6539834   .08855005
    100036 2007   .11130834 -.010829791
    end
    Sorted by year the data looks as follows:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long mfiid int year float(_roe _sp500)
    100324 2003       .13935 .2237602
    100118 2003      -.05345 .2237602
    100296 2003       .18615 .2237602
    100092 2003      -.05935 .2237602
    100720 2003       .14455 .2237602
    100104 2003      -.02805 .2237602
    101107 2003   .015449997 .2237602
    100648 2003       .08945 .2237602
    100302 2003       .16415 .2237602
    100467 2003       .40555 .2237602
    100303 2003       .14535 .2237602
    100281 2003       .23025 .2237602
    100523 2003       .08065 .2237602
    100326 2003       .10955 .2237602
    100673 2003       .71915 .2237602
    100211 2003  -.066250004 .2237602
    100096 2003      -.11025 .2237602
    100492 2003      -.22445 .2237602
    100312 2003       .06345 .2237602
    100431 2003       .02765 .2237602
    100565 2003       .55315 .2237602
    100477 2003       .08275 .2237602
    100713 2003      -.04965 .2237602
    100547 2003  -.036650002 .2237602
    100684 2003       .07855 .2237602
    100556 2003       .05095 .2237602
    100404 2003       .07495 .2237602
    100280 2003       .25795 .2237602
    100080 2003       .19575 .2237602
    100288 2003       .04715 .2237602
    100309 2003       .01885 .2237602
    100253 2003     -2.49875 .2237602
    100127 2003      -.46735 .2237602
    100749 2003  -.012650002 .2237602
    100357 2003       .09915 .2237602
    100617 2003      -.18485 .2237602
    100027 2003    1.0200499 .2237602
    100255 2003   .011749998 .2237602
    100346 2003       .22665 .2237602
    100233 2003   .007949997 .2237602
    100348 2003       .08205 .2237602
    100350 2003       .05175 .2237602
    100813 2003       .14445 .2237602
    100741 2003       .14795 .2237602
    100155 2003      -.02585 .2237602
    100243 2003       .09685 .2237602
    100173 2003      -.05955 .2237602
    100733 2003  -.011250002 .2237602
    100664 2003       .31375 .2237602
    100705 2003       .16505 .2237602
    100678 2003      -.02375 .2237602
    100590 2003      -.22435 .2237602
    100378 2003      -.01945 .2237602
    100188 2003 -.0014500022 .2237602
    100700 2003       .36955 .2237602
    100420 2003       .05695 .2237602
    100500 2003       .04465 .2237602
    100402 2003       .23905 .2237602
    100298 2003       .19165 .2237602
    100716 2003       .19895 .2237602
    100542 2003    .26064998 .2237602
    100339 2003       .39035 .2237602
    100641 2003      -.02645 .2237602
    100168 2003  -.072850004 .2237602
    100158 2003      -.27875 .2237602
    100097 2003       .39195 .2237602
    100611 2003   -.28904998 .2237602
    100512 2003       .46595 .2237602
    100299 2003       .50835 .2237602
    100225 2003       .50175 .2237602
    100036 2003      1.58285 .2237602
    100386 2003       .15465 .2237602
    100329 2003       .01035 .2237602
    100017 2003       .17895 .2237602
    100576 2003   -.29035002 .2237602
    100442 2003       .12485 .2237602
    100831 2003       .06045 .2237602
    100089 2003      -.37675 .2237602
    100601 2003    .27354997 .2237602
    100769 2003      -.16215 .2237602
    100747 2003       .11985 .2237602
    100515 2003       .08925 .2237602
    100222 2003      -.06445 .2237602
    100765 2003      -.02665 .2237602
    100681 2003      -.03485 .2237602
    100217 2003   .005849998 .2237602
    100098 2003      -.08055 .2237602
    100540 2003   .018349998 .2237602
    100464 2003       .01055 .2237602
    100660 2003  -.005450003 .2237602
    100574 2003      -.02425 .2237602
    100236 2003       .17965 .2237602
    100205 2003  -.018150002 .2237602
    100369 2003      -.02675 .2237602
    100714 2003       .33685 .2237602
    100497 2003      -.05555 .2237602
    100376 2003       .11915 .2237602
    100325 2003       .00925 .2237602
    100666 2003   .009949997 .2237602
    100242 2003       .11325 .2237602
    end

    Help is highly appreciated. Thanks a lot in advance!

    Kind regards,
    Rafael
    Last edited by Rafael Maschke; 11 Feb 2020, 14:09. Reason: correction

  • #2
    From your description, I can't tell if you want to do a separate regression for each year, with the various mfiid's being the different observations in the regression sample, or the other way around: a separate regression for each mfiid, with the years giving the different observations in the regression sample. For illustrative purposes, I'll assume the latter:

    Code:
    rangestat (reg) _roe _sp500, by(mfiid) interval(year . .)
    -rangestat- is written by Robert Picard, Nick Cox, and Roberto Ferrer; it is available from SSC.

    Comment


    • #3
      Dear Clyde Schechter,

      thanks a lot for your response and this very useful code. The assumption you made correctly applies to my project. Sorry for being unclear.

      I have also used this code in order to determine the beta of two groups within the panel data (profit_status):

      Code:
       rangestat (reg) _roe _sp500, by(profit_status) interval(year . .)
      I have a question regarding the beta estimates I would like to ask you. Does the resulting beta for each Non-profit and Profit subgroup over the years take into account the panel data gaps in such a way that mfiid's that are subject to a shorter or longer time period add their corresponding weight to the beta estimate(s)? I am not sure if this makes sense, but I reckoned that beta's with shorter time intervals, say 3 years, should give a lower weight to the average (e.g.) "Profit" beta estimate than beta's with 8 years of data.


      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input int year long mfiid str10 profit_status float(_roe _sp500) double(mfiid_beta profitstatus_beta)
      2007 100000 "Non-profit"    .2913083 -.010829791 -.01230429498659591  .0676808639326907
      2008 100000 "Non-profit"   .17713334   -.4216229 -.01230429498659591  .0676808639326907
      2009 100000 "Non-profit"   .14123334     .201956 -.01230429498659591  .0676808639326907
      2004 100001 "Non-profit"   .04955833    .0472585 -.43151791583880483  .0676808639326907
      2005 100001 "Non-profit" -.008699998  -.01277183 -.43151791583880483  .0676808639326907
      2006 100001 "Non-profit"   .02328333   .08855005 -.43151791583880483  .0676808639326907
      2007 100001 "Non-profit"   .21060835 -.010829791 -.43151791583880483  .0676808639326907
      2009 100001 "Non-profit"  .015933335     .201956 -.43151791583880483  .0676808639326907
      2010 100001 "Non-profit"  .017058332   .09580792 -.43151791583880483  .0676808639326907
      2008 100004 "Profit"       .20683333   -.4216229                   . .22769555983445572
      2006 100008 "Non-profit"   -.4828166   .08855005   15.21401296646321  .0676808639326907
      2007 100008 "Non-profit"   -.4197917 -.010829791   15.21401296646321  .0676808639326907
      2008 100008 "Non-profit"  -2.9300666   -.4216229   15.21401296646321  .0676808639326907
      2009 100008 "Non-profit"    9.721633     .201956   15.21401296646321  .0676808639326907
      2005 100012 "Non-profit"       .3659  -.01277183 -1.3618103679868323  .0676808639326907
      2006 100012 "Non-profit"   -.4431167   .08855005 -1.3618103679868323  .0676808639326907
      2007 100012 "Non-profit"   1.6969082 -.010829791 -1.3618103679868323  .0676808639326907
      2008 100012 "Non-profit"   1.2119334   -.4216229 -1.3618103679868323  .0676808639326907
      2009 100012 "Non-profit"    .9820334     .201956 -1.3618103679868323  .0676808639326907
      2010 100012 "Non-profit"   .16185834   .09580792 -1.3618103679868323  .0676808639326907
      2009 100013 "Non-profit"  -.10906667     .201956                   .  .0676808639326907
      2010 100013 "Non-profit"  -.13484167   .09580792                   .  .0676808639326907
      2005 100016 "Profit"          -.0101  -.01277183 .015465619825001544 .22769555983445572
      2006 100016 "Profit"     .0035833344   .08855005 .015465619825001544 .22769555983445572
      2007 100016 "Profit"      .016408335 -.010829791 .015465619825001544 .22769555983445572
      2008 100016 "Profit"       .05173333   -.4216229 .015465619825001544 .22769555983445572
      2009 100016 "Profit"       .07153333     .201956 .015465619825001544 .22769555983445572
      2010 100016 "Profit"       .08925833   .09580792 .015465619825001544 .22769555983445572
      2003 100017 "Profit"          .17895    .2237602  .18605594287548533 .22769555983445572
      2004 100017 "Profit"       .16935833    .0472585  .18605594287548533 .22769555983445572
      2006 100017 "Profit"       .09988333   .08855005  .18605594287548533 .22769555983445572
      2007 100020 "Profit"      .003608331 -.010829791  .09572634580600582 .22769555983445572
      2008 100020 "Profit"      .010133334   -.4216229  .09572634580600582 .22769555983445572
      2009 100020 "Profit"       .09823333     .201956  .09572634580600582 .22769555983445572
      2010 100020 "Profit"      .016058333   .09580792  .09572634580600582 .22769555983445572
      2005 100021 "Profit"          -.0768  -.01277183 .030577672464920214 .22769555983445572
      2006 100021 "Profit"      -.05961667   .08855005 .030577672464920214 .22769555983445572
      2007 100021 "Profit"     -.017191667 -.010829791 .030577672464920214 .22769555983445572
      2008 100021 "Profit"      -.04696666   -.4216229 .030577672464920214 .22769555983445572
      2009 100021 "Profit"     -.023466665     .201956 .030577672464920214 .22769555983445572
      2010 100021 "Profit"     -.014741667   .09580792 .030577672464920214 .22769555983445572
      2006 100024 "Non-profit"    .9799833   .08855005  -.2686100941367364  .0676808639326907
      2009 100024 "Non-profit"   .51533335     .201956  -.2686100941367364  .0676808639326907
      2010 100024 "Non-profit"  .014058333   .09580792  -.2686100941367364  .0676808639326907
      2004 100026 "Non-profit"   17.870058    .0472585   8.093220141687869  .0676808639326907
      2005 100026 "Non-profit"       -5.09  -.01277183   8.093220141687869  .0676808639326907
      2006 100026 "Non-profit"    9.523084   .08855005   8.093220141687869  .0676808639326907
      2007 100026 "Non-profit"  -2.4865916 -.010829791   8.093220141687869  .0676808639326907
      2008 100026 "Non-profit"   .54033333   -.4216229   8.093220141687869  .0676808639326907
      2009 100026 "Non-profit"   1.4377333     .201956   8.093220141687869  .0676808639326907
      2010 100026 "Non-profit"    .4943583   .09580792   8.093220141687869  .0676808639326907
      2003 100027 "Profit"       1.0200499    .2237602  1.0082801249665767 .22769555983445572
      2004 100027 "Profit"        .8740584    .0472585  1.0082801249665767 .22769555983445572
      2005 100027 "Profit"           .7555  -.01277183  1.0082801249665767 .22769555983445572
      2006 100027 "Profit"       .16448334   .08855005  1.0082801249665767 .22769555983445572
      2006 100029 "Profit"      -.16821668   .08855005  -.1929731451801049 .22769555983445572
      2007 100029 "Profit"       .27910832 -.010829791  -.1929731451801049 .22769555983445572
      2008 100029 "Profit"       .07793334   -.4216229  -.1929731451801049 .22769555983445572
      2009 100029 "Profit"      .005633332     .201956  -.1929731451801049 .22769555983445572
      2005 100030 "Profit"          -.0131  -.01277183 -.07494323541065033 .22769555983445572
      2006 100030 "Profit"      .024183333   .08855005 -.07494323541065033 .22769555983445572
      2007 100030 "Profit"       .02750833 -.010829791 -.07494323541065033 .22769555983445572
      2008 100030 "Profit"       .05113334   -.4216229 -.07494323541065033 .22769555983445572
      2005 100031 "Non-profit"        -.02  -.01277183   .8757502637805205  .0676808639326907
      2006 100031 "Non-profit"  -.03771666   .08855005   .8757502637805205  .0676808639326907
      2007 100031 "Non-profit" -.033691667 -.010829791   .8757502637805205  .0676808639326907
      2009 100031 "Non-profit"   .14953333     .201956   .8757502637805205  .0676808639326907
      2010 100031 "Non-profit"   .19615833   .09580792   .8757502637805205  .0676808639326907
      2004 100032 "Profit"       .06425834    .0472585  -.1563752523359082 .22769555983445572
      2005 100032 "Profit"          -.0216  -.01277183  -.1563752523359082 .22769555983445572
      2008 100032 "Profit"       .17953333   -.4216229  -.1563752523359082 .22769555983445572
      2010 100032 "Profit"       .17735833   .09580792  -.1563752523359082 .22769555983445572
      2005 100033 "Profit"        .9403999  -.01277183  .36818820953588766 .22769555983445572
      2006 100033 "Profit"        .7986833   .08855005  .36818820953588766 .22769555983445572
      2007 100033 "Profit"       .07110833 -.010829791  .36818820953588766 .22769555983445572
      2008 100033 "Profit"       .05233334   -.4216229  .36818820953588766 .22769555983445572
      2009 100033 "Profit"       .03813333     .201956  .36818820953588766 .22769555983445572
      2010 100033 "Profit"       .23085834   .09580792  .36818820953588766 .22769555983445572
      2003 100036 "Profit"         1.58285    .2237602  2.4887138330042635 .22769555983445572
      2004 100036 "Profit"        16.50846    .0472585  2.4887138330042635 .22769555983445572
      2005 100036 "Profit"           .0053  -.01277183  2.4887138330042635 .22769555983445572
      2006 100036 "Profit"        .6539834   .08855005  2.4887138330042635 .22769555983445572
      2007 100036 "Profit"       .11130834 -.010829791  2.4887138330042635 .22769555983445572
      2008 100036 "Profit"     -.025066666   -.4216229  2.4887138330042635 .22769555983445572
      2009 100036 "Profit"     -.006966667     .201956  2.4887138330042635 .22769555983445572
      2010 100036 "Profit"       .03235833   .09580792  2.4887138330042635 .22769555983445572
      2003 100039 "Profit"         -.15105    .2237602 -1.3043965932947752 .22769555983445572
      2004 100039 "Profit"      -.10604167    .0472585 -1.3043965932947752 .22769555983445572
      2005 100039 "Profit"           .2303  -.01277183 -1.3043965932947752 .22769555983445572
      2006 100039 "Profit"     -.008116666   .08855005 -1.3043965932947752 .22769555983445572
      2005 100041 "Non-profit"       .6233  -.01277183   .7659891154256351  .0676808639326907
      2006 100041 "Non-profit"    .9760834   .08855005   .7659891154256351  .0676808639326907
      2007 100041 "Non-profit"   .25010833 -.010829791   .7659891154256351  .0676808639326907
      2008 100041 "Non-profit"   .36893335   -.4216229   .7659891154256351  .0676808639326907
      2008 100042 "Profit"      -.22946666   -.4216229 -.19658897029645822 .22769555983445572
      2009 100042 "Profit"      -.52516663     .201956 -.19658897029645822 .22769555983445572
      2010 100042 "Profit"      -.02404167   .09580792 -.19658897029645822 .22769555983445572
      2004 100043 "Profit"       -6.986542    .0472585 -13.055812227775231 .22769555983445572
      2005 100043 "Profit"           .2743  -.01277183 -13.055812227775231 .22769555983445572
      2006 100043 "Profit"       1.2188834   .08855005 -13.055812227775231 .22769555983445572
      end
      format %ty year
      Kind regards,
      Rafael

      Comment


      • #4
        Originally posted by Rafael Maschke View Post
        Dear Clyde Schechter,

        thanks a lot for your response and this very useful code. The assumption you made correctly applies to my project. Sorry for being unclear.

        I have also used this code in order to determine the beta of two groups within the panel data (profit_status):

        Code:
         rangestat (reg) _roe _sp500, by(profit_status) interval(year . .)
        I have a question regarding the beta estimates I would like to ask you. Does the resulting beta for each Non-profit and Profit subgroup over the years take into account the panel data gaps in such a way that mfiid's that are subject to a shorter or longer time period add their corresponding weight to the beta estimate(s)? I am not sure if this makes sense, but I reckoned that beta's with shorter time intervals, say 3 years, should give a lower weight to the average (e.g.) "Profit" beta estimate than beta's with 8 years of data.


        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input int year long mfiid str10 profit_status float(_roe _sp500) double(mfiid_beta profitstatus_beta)
        2007 100000 "Non-profit" .2913083 -.010829791 -.01230429498659591 .0676808639326907
        2008 100000 "Non-profit" .17713334 -.4216229 -.01230429498659591 .0676808639326907
        2009 100000 "Non-profit" .14123334 .201956 -.01230429498659591 .0676808639326907
        2004 100001 "Non-profit" .04955833 .0472585 -.43151791583880483 .0676808639326907
        2005 100001 "Non-profit" -.008699998 -.01277183 -.43151791583880483 .0676808639326907
        2006 100001 "Non-profit" .02328333 .08855005 -.43151791583880483 .0676808639326907
        2007 100001 "Non-profit" .21060835 -.010829791 -.43151791583880483 .0676808639326907
        2009 100001 "Non-profit" .015933335 .201956 -.43151791583880483 .0676808639326907
        2010 100001 "Non-profit" .017058332 .09580792 -.43151791583880483 .0676808639326907
        2008 100004 "Profit" .20683333 -.4216229 . .22769555983445572
        2006 100008 "Non-profit" -.4828166 .08855005 15.21401296646321 .0676808639326907
        2007 100008 "Non-profit" -.4197917 -.010829791 15.21401296646321 .0676808639326907
        2008 100008 "Non-profit" -2.9300666 -.4216229 15.21401296646321 .0676808639326907
        2009 100008 "Non-profit" 9.721633 .201956 15.21401296646321 .0676808639326907
        2005 100012 "Non-profit" .3659 -.01277183 -1.3618103679868323 .0676808639326907
        2006 100012 "Non-profit" -.4431167 .08855005 -1.3618103679868323 .0676808639326907
        2007 100012 "Non-profit" 1.6969082 -.010829791 -1.3618103679868323 .0676808639326907
        2008 100012 "Non-profit" 1.2119334 -.4216229 -1.3618103679868323 .0676808639326907
        2009 100012 "Non-profit" .9820334 .201956 -1.3618103679868323 .0676808639326907
        2010 100012 "Non-profit" .16185834 .09580792 -1.3618103679868323 .0676808639326907
        2009 100013 "Non-profit" -.10906667 .201956 . .0676808639326907
        2010 100013 "Non-profit" -.13484167 .09580792 . .0676808639326907
        2005 100016 "Profit" -.0101 -.01277183 .015465619825001544 .22769555983445572
        2006 100016 "Profit" .0035833344 .08855005 .015465619825001544 .22769555983445572
        2007 100016 "Profit" .016408335 -.010829791 .015465619825001544 .22769555983445572
        2008 100016 "Profit" .05173333 -.4216229 .015465619825001544 .22769555983445572
        2009 100016 "Profit" .07153333 .201956 .015465619825001544 .22769555983445572
        2010 100016 "Profit" .08925833 .09580792 .015465619825001544 .22769555983445572
        2003 100017 "Profit" .17895 .2237602 .18605594287548533 .22769555983445572
        2004 100017 "Profit" .16935833 .0472585 .18605594287548533 .22769555983445572
        2006 100017 "Profit" .09988333 .08855005 .18605594287548533 .22769555983445572
        2007 100020 "Profit" .003608331 -.010829791 .09572634580600582 .22769555983445572
        2008 100020 "Profit" .010133334 -.4216229 .09572634580600582 .22769555983445572
        2009 100020 "Profit" .09823333 .201956 .09572634580600582 .22769555983445572
        2010 100020 "Profit" .016058333 .09580792 .09572634580600582 .22769555983445572
        2005 100021 "Profit" -.0768 -.01277183 .030577672464920214 .22769555983445572
        2006 100021 "Profit" -.05961667 .08855005 .030577672464920214 .22769555983445572
        2007 100021 "Profit" -.017191667 -.010829791 .030577672464920214 .22769555983445572
        2008 100021 "Profit" -.04696666 -.4216229 .030577672464920214 .22769555983445572
        2009 100021 "Profit" -.023466665 .201956 .030577672464920214 .22769555983445572
        2010 100021 "Profit" -.014741667 .09580792 .030577672464920214 .22769555983445572
        2006 100024 "Non-profit" .9799833 .08855005 -.2686100941367364 .0676808639326907
        2009 100024 "Non-profit" .51533335 .201956 -.2686100941367364 .0676808639326907
        2010 100024 "Non-profit" .014058333 .09580792 -.2686100941367364 .0676808639326907
        2004 100026 "Non-profit" 17.870058 .0472585 8.093220141687869 .0676808639326907
        2005 100026 "Non-profit" -5.09 -.01277183 8.093220141687869 .0676808639326907
        2006 100026 "Non-profit" 9.523084 .08855005 8.093220141687869 .0676808639326907
        2007 100026 "Non-profit" -2.4865916 -.010829791 8.093220141687869 .0676808639326907
        2008 100026 "Non-profit" .54033333 -.4216229 8.093220141687869 .0676808639326907
        2009 100026 "Non-profit" 1.4377333 .201956 8.093220141687869 .0676808639326907
        2010 100026 "Non-profit" .4943583 .09580792 8.093220141687869 .0676808639326907
        2003 100027 "Profit" 1.0200499 .2237602 1.0082801249665767 .22769555983445572
        2004 100027 "Profit" .8740584 .0472585 1.0082801249665767 .22769555983445572
        2005 100027 "Profit" .7555 -.01277183 1.0082801249665767 .22769555983445572
        2006 100027 "Profit" .16448334 .08855005 1.0082801249665767 .22769555983445572
        2006 100029 "Profit" -.16821668 .08855005 -.1929731451801049 .22769555983445572
        2007 100029 "Profit" .27910832 -.010829791 -.1929731451801049 .22769555983445572
        2008 100029 "Profit" .07793334 -.4216229 -.1929731451801049 .22769555983445572
        2009 100029 "Profit" .005633332 .201956 -.1929731451801049 .22769555983445572
        2005 100030 "Profit" -.0131 -.01277183 -.07494323541065033 .22769555983445572
        2006 100030 "Profit" .024183333 .08855005 -.07494323541065033 .22769555983445572
        2007 100030 "Profit" .02750833 -.010829791 -.07494323541065033 .22769555983445572
        2008 100030 "Profit" .05113334 -.4216229 -.07494323541065033 .22769555983445572
        2005 100031 "Non-profit" -.02 -.01277183 .8757502637805205 .0676808639326907
        2006 100031 "Non-profit" -.03771666 .08855005 .8757502637805205 .0676808639326907
        2007 100031 "Non-profit" -.033691667 -.010829791 .8757502637805205 .0676808639326907
        2009 100031 "Non-profit" .14953333 .201956 .8757502637805205 .0676808639326907
        2010 100031 "Non-profit" .19615833 .09580792 .8757502637805205 .0676808639326907
        2004 100032 "Profit" .06425834 .0472585 -.1563752523359082 .22769555983445572
        2005 100032 "Profit" -.0216 -.01277183 -.1563752523359082 .22769555983445572
        2008 100032 "Profit" .17953333 -.4216229 -.1563752523359082 .22769555983445572
        2010 100032 "Profit" .17735833 .09580792 -.1563752523359082 .22769555983445572
        2005 100033 "Profit" .9403999 -.01277183 .36818820953588766 .22769555983445572
        2006 100033 "Profit" .7986833 .08855005 .36818820953588766 .22769555983445572
        2007 100033 "Profit" .07110833 -.010829791 .36818820953588766 .22769555983445572
        2008 100033 "Profit" .05233334 -.4216229 .36818820953588766 .22769555983445572
        2009 100033 "Profit" .03813333 .201956 .36818820953588766 .22769555983445572
        2010 100033 "Profit" .23085834 .09580792 .36818820953588766 .22769555983445572
        2003 100036 "Profit" 1.58285 .2237602 2.4887138330042635 .22769555983445572
        2004 100036 "Profit" 16.50846 .0472585 2.4887138330042635 .22769555983445572
        2005 100036 "Profit" .0053 -.01277183 2.4887138330042635 .22769555983445572
        2006 100036 "Profit" .6539834 .08855005 2.4887138330042635 .22769555983445572
        2007 100036 "Profit" .11130834 -.010829791 2.4887138330042635 .22769555983445572
        2008 100036 "Profit" -.025066666 -.4216229 2.4887138330042635 .22769555983445572
        2009 100036 "Profit" -.006966667 .201956 2.4887138330042635 .22769555983445572
        2010 100036 "Profit" .03235833 .09580792 2.4887138330042635 .22769555983445572
        2003 100039 "Profit" -.15105 .2237602 -1.3043965932947752 .22769555983445572
        2004 100039 "Profit" -.10604167 .0472585 -1.3043965932947752 .22769555983445572
        2005 100039 "Profit" .2303 -.01277183 -1.3043965932947752 .22769555983445572
        2006 100039 "Profit" -.008116666 .08855005 -1.3043965932947752 .22769555983445572
        2005 100041 "Non-profit" .6233 -.01277183 .7659891154256351 .0676808639326907
        2006 100041 "Non-profit" .9760834 .08855005 .7659891154256351 .0676808639326907
        2007 100041 "Non-profit" .25010833 -.010829791 .7659891154256351 .0676808639326907
        2008 100041 "Non-profit" .36893335 -.4216229 .7659891154256351 .0676808639326907
        2008 100042 "Profit" -.22946666 -.4216229 -.19658897029645822 .22769555983445572
        2009 100042 "Profit" -.52516663 .201956 -.19658897029645822 .22769555983445572
        2010 100042 "Profit" -.02404167 .09580792 -.19658897029645822 .22769555983445572
        2004 100043 "Profit" -6.986542 .0472585 -13.055812227775231 .22769555983445572
        2005 100043 "Profit" .2743 -.01277183 -13.055812227775231 .22769555983445572
        2006 100043 "Profit" 1.2188834 .08855005 -13.055812227775231 .22769555983445572
        end
        format %ty year
        Kind regards,
        Rafael




        1. If I use the rangestat code above by profit_status I get the same results as with a simple linear regression:

        Code:
        reg _roe _sp500 if profit_status == "Profit"
        =
        Code:
        rangestat (reg) _roe _sp500, by(profit_status) interval(year . .)


        2. I also tried to follow -help rangestat- and added a by option at the end of the code [options], but I get the error message "by not allowed":
        Code:
        rangestat (reg) _roe _sp500, by(mfiid) interval(year . .) by profit_status

        3. I have tried this code, which gives me the right estimates for Profit-mfiids:
        Code:
         rangestat (reg) _roe _sp500 if profit_status == "Profit", by(mfiid) interval(year . .)
        Is there a way to execute step three for both profit_status groups at once?
        Last edited by Rafael Maschke; 12 Feb 2020, 18:50. Reason: Correction

        Comment


        • #5
          Yes. Your error was in trying to specify -by()- twice (and, on top of that, omitting the parentheses the second time)..

          Code:
          rangestat (reg) _roe _sp500 by(mfiid profit_status) interval(year . .)
          As for your question in #3, I'm not sure what kind of "weighting" you are talking about here. Each regression is carried out with exactly the number of observations that meet the conditions specified by -by()- and -interval()- and have non-missing values for _roe and _sp500. No more and no less. The results you get are the same as you would get if you did each of those regressions separately with corresponding -if- conditions. It's just normal regression. And that is what is usually wanted here. But it is not, in the formal statistical sense of the term, "weighting." If you do have some kind of weighting, in the statistical sense of the term, in mind then please post back with a full explanation.

          Comment


          • #6
            Thanks a lot for helping me out Clyde!

            Comment

            Working...
            X