Announcement

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

  • Invalid name

    Hello everyone,
    I would like to kindly ask the community for a help. I use STATA 16, Windows 10. When I run the code:

    . capture program drop capm

    . program define capm, rclass
    1. syntax varlist(min=2 max=2 numeric) [if], RFrate(varname)
    2. local stockret: word 1 of `varlist´
    3. local mktret: word 2 of `varlist´
    4. cap drop prem`stock´
    5. qui gen prem`stock´=`stockret´-`rfrate´
    6. cap drop mktpremium
    7. qui gen mktpremium=`mktret´-`rfrate´
    8. cap reg prem`stock´ mktpremium `if´
    9. if _rc==0 & r(N)>30 {
    10. matrix res= r(table)
    11. local b1=res[1,1]
    12. local b0=res[1,2]
    13. local SEb1=res[2,1]
    14. local SEb0=res[2,2]
    15. local N=e(N)
    16. dis "Market beta is " %3.2f `b1´ "; std. error of beta is " %8.6f `SEb1´
    17. dis "Alpha is " %8.6f `b0´ "; std. error of alpha is " %8.6f `SEb0´
    18. return scalar b1=`b1´
    19. return scalar b0=`b0´
    20. return scalar SEb1=`SEb1´
    21. return scalar SEb0=`SEb0´
    22. return scalar N=`N´
    23. }
    24. end

    . qui freduse TB3MS, clear

    . qui gen m_Rf = (TB3MS/100)/12

    . qui gen m_rf = ln(1 + m_Rf)

    . qui gen period =mofd(daten)

    . format period %tm

    . qui tsset period

    . cap getsymbols ^GSPC CAG, fy(2014) freq(m) yahoo clear price(adjclose)

    . qui merge 1:1 period using rfrate, keepusing(m_rf)

    . qui drop if _merge!=3

    . qui drop _merge

    . capm r_CAG r__GSPC, rfrate(m_rf)


    I get "invalid name r(198);" error. May I ask you ladies and gentlemen to tell me what is wrong? I tried with different .do files with and without saving and I still face the same problem. The code comes from a conference on measuring abnormal returns of stock and everything comes from a file shares with audience.

    Best Regards,
    Rafał

  • #2
    The local macro stock is not defined in this program. So, Stata will see


    Code:
    cap drop prem`stock´
     qui gen prem`stock´=`stockret´-`rfrate´
     cap drop mktpremium
     qui gen mktpremium=`mktret´-`rfrate´
     cap reg prem`stock´ mktpremium `if´

    as if it were

    Code:
    cap drop prem
     qui gen prem =`stockret´-`rfrate´
     cap drop mktpremium
     qui gen mktpremium=`mktret´-`rfrate´
     cap reg prem  mktpremium `if´
    I don't know if that is problematic. I didn't try downloading any data.

    Most crucially, where does the code fail? You may need to take out some qui and cap to see where it fails.

    Comment

    Working...
    X