Announcement

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

  • Translation Problems

    Dear Stata users,

    I am doing a thesis on mutual fund performance for which I use the Carhart and Fama-French factor models
    So three or four explanatory variables (RMRF, SMB, HML and the Carhart factor MOM) to generate fund alphas (the constant), using the returns of mutual funds as dependent variable.
    Lucky enough, I found an online thesis that did a similar research as I did (Martineer, 2013). He uses the following code (starting at line 1060 in the do.file):

    **Running the model and saving results:
    **The model was also run using Newey-West adjusted standard errors for the t-statistics
    tempfile abc
    tempname def
    postfile `def' str32 fund alpha_b alpha_se mkt_b mkt_se smb_b smb_se hml_b hml_se mom_b mom_se rsquared

    adjrsquared sic obs normal_p heterosked_p bg1_p bg6_p bg12_p using "`abc'", replace
    foreach x of varlist ipaustraliansmallcompanies-zurichinvausvalueretailshrfd {
    reg `x' RM_RF SMB HML MOM
    quietly predict res, residual
    quietly sktest res
    scalar skpval = r(P_chi2)
    estat hettest
    scalar bppval = r(p)
    estat bgodfrey, lags(1)
    matrix bg1 = r(p)
    estadd scalar bg1 = bg1[1,1]
    estat bgodfrey, lags(6)
    matrix bg6 = r(p)
    estadd scalar bg6 = bg6[1,1]
    estat bgodfrey, lags(12)
    matrix bg12 = r(p)
    estadd scalar bg12 = bg12[1,1]
    mat ci = e(ci_bc)
    quietly ereturn list
    estat ic
    matrix ic = r(S)
    estadd scalar sic = ic[1,6]
    post `def' ("`e(depvar)'") (_b[_cons]) (_se[_cons]) (_b[RM_RF]) (_se[RM_RF]) (_b[SMB]) (_se[SMB]) (_b

    [HML]) (_se[HML]) (_b[MOM]) (_se[MOM]) (e(r2)) (e(r2_a)) (e(sic)) (e(N)) (skpval) (bppval) (e(bg1)) (e

    (bg6)) (e(bg12))
    drop res
    }
    postclose `def'
    use "`abc'", clear

    *Summarising the coefficients on the four factors, for each fund:
    sum alpha_b mkt_b smb_b hml_b mom_b
    gsort -alpha_b
    gen rank=_n


    However, when translating the code to my own dataset I get error codes and Stata remains 'too busy' to execute new orders.
    Can anyone help me make the translation to my dataset? For me the varlist is AddVaue-Allianz (these are the different mutual funds).
    The only other variables are the time-series data of RM_RF, SMB, HML and MOM.
    I am not an experienced Stata user and I could really use some help.

    Kind regards,

    Melvin Kool
    Attached Files
    Last edited by Melvin Kool; 08 Jul 2017, 05:47.

  • #2
    If you need more (context) information to help me, please let me know and I'll provide it.

    Comment


    • #3
      Welcome to Statalist, Melvin.

      Indeed we do need more information to be able to assist. Please review the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post. Note especially sections 9-12 on how to best pose your question. It's particularly helpful to copy commands and output from your Stata Results window and paste them into your Statalist post using CODE delimiters, and to use the dataex command to provide sample data, as described in section 12 of the FAQ.

      The more you help others understand your problem, the more likely others are to be able to help you solve your problem.

      Section 12.1 is particularly pertinent

      12.1 What to say about your commands and your problem

      Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!
      So in particular "I get error codes" provides no information to help us understand what is going wrong. While in theory someone might be able to read your 3177 lines of code, guess where the command is that's giving you problems, and then guess what those problems might be, it does seem unlikely.


      Comment


      • #4
        Thank you for the reply mr. Lisowski,

        The error code I mostly get is that I don't have a varlist for the postfile. I have tried to create one using

        Code:
        local x AddValue-Allianz
        Then I continue with:

        Code:
        tempfile abc
        tempname def
        postfile `def' str32 fund alpha_b alpha_se mkt_b mkt_se smb_b smb_se hml_b hml_se mom_b mom_se rsquared
        But time after time Stata gives error code r(100), stating 'a varlist is required'. How can I connect my varlist AddValue-Allianz to postfile `def' and define the variables I want to show (coefficient, t-statistic, p-value, adjusted rsquared)?

        Really appreciate your help

        Comment


        • #5
          You misunderstand how postfile is used. I can do no better than to refer you to the documentation, especially the example, provided by help postfile.

          Comment


          • #6
            You need to reconnect some lines that have been split and are further separated by a blank line. The following runs OK:

            Code:
            clear all
            set seed 312312
            set obs 100
            gen t = _n
            tsset t
            gen ipaustraliansmallcompanies = runiform()
            gen zurichinvausvalueretailshrfd = runiform()
            gen RM_RF = runiform()
            gen SMB = runiform()
            gen HML = runiform()
            gen MOM = runiform()
            
            **Running the model and saving results:
            **The model was also run using Newey-West adjusted standard errors for the t-statistics
            tempfile abc
            tempname def
            postfile `def' str32 fund alpha_b alpha_se mkt_b mkt_se smb_b smb_se hml_b hml_se mom_b mom_se ///
                rsquared adjrsquared sic obs normal_p heterosked_p bg1_p bg6_p bg12_p using "`abc'", replace
                
            foreach x of varlist ipaustraliansmallcompanies-zurichinvausvalueretailshrfd {
                reg `x' RM_RF SMB HML MOM
                quietly predict res, residual
                quietly sktest res
                scalar skpval = r(P_chi2)
                estat hettest
                scalar bppval = r(p)
                estat bgodfrey, lags(1)
                matrix bg1 = r(p)
                estadd scalar bg1 = bg1[1,1]
                estat bgodfrey, lags(6)
                matrix bg6 = r(p)
                estadd scalar bg6 = bg6[1,1]
                estat bgodfrey, lags(12)
                matrix bg12 = r(p)
                estadd scalar bg12 = bg12[1,1]
                mat ci = e(ci_bc)
                quietly ereturn list
                estat ic
                matrix ic = r(S)
                estadd scalar sic = ic[1,6]
                post `def' ("`e(depvar)'") (_b[_cons]) (_se[_cons]) (_b[RM_RF]) (_se[RM_RF]) (_b[SMB]) ///
                    (_se[SMB]) (_b[HML]) (_se[HML]) (_b[MOM]) (_se[MOM]) (e(r2)) (e(r2_a)) (e(sic)) (e(N)) ///
                    (skpval) (bppval) (e(bg1)) (e(bg6)) (e(bg12))
                drop res
            }
            postclose `def'
            use "`abc'", clear
            
            *Summarising the coefficients on the four factors, for each fund:
            sum alpha_b mkt_b smb_b hml_b mom_b
            gsort -alpha_b
            gen rank=_n

            Comment


            • #7
              Thank you Robert, the problem was indeed in the blanks, I can now run the regressions!

              Comment


              • #8
                Dear Stata users,

                I am doing similar research as Melvin.

                When I copy the syntax into my do-file, it gives the following error: command estadd is unrecognized. How can I fix this?

                Best regards, Rens Eggink

                Comment

                Working...
                X