Announcement

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

  • #61
    First: as a general practice, when you get no results with -runby-, you should do it again with the -verbose- option specified. That way you will see the error messages generated by the program that -runby- is iterating. Of course, those will be interspersed with a flood of output, but they are usually not that hard to find since they are in red.

    In this instance, though I see the mistake. The line -local denom = r(var)- is the problem. There are two things wrong with it.
    1. Presumably your intent is to get the variance of some variable that has just been put through the -summarize- command. But there is non -summarize- command preceding that. The preceding command is instead a -tsset- command. -tsset- returns a lot of tings in -r()- but none of them are variances. And if there were an earlier -summarize- command, whatever it left behind in -r()- would have been overwritten by the -tsset-.
    2. Even if you did have a -summarize- command immediately before the -local denom = r(var)- command, -summarize- does not leave behind an -r(var)-. It leaves behind -r(Var)-. Everything in Stata is case sensitive. I'm not sure why, of all the things left behind by -summarize-, this one, and only this one, is capitalized, but that's the way it is, and you have to program accordingly.
    In the future, when showing data examples, please use the -dataex- command to do so. If you are running version 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.
    Last edited by Clyde Schechter; 23 Feb 2023, 08:57.

    Comment


    • #62
      Thanks a lot for your help! I tried it again and adjusted the local denim, but it still does not work. Unfortunately I can't find anything about the verbose command.
      Now I extracted the data, as you suggested, maybe I did something wrong. Thanks again so much!

      [CODE]
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input str6 GVKEY str4 iid long datadate str8 tic str70 conm double(ajexdi prccd trfd) float(prccd_L1 ajexdi_L1 trfd_L1 N Z daily_tot_return) double ValueWeightedReturnincldivi byte _merge long tic_1
      "126554" "01" 16072 "A" "AGILENT TECHNOLOGIES INC" 1 28.8 1 108.03 1 2.317898 28.8 250.40253 -.8849852 -.0027175980000000003 3 1
      "126554" "01" 16075 "A" "AGILENT TECHNOLOGIES INC" 1 29.55 1 28.8 1 1 29.55 28.8 .02604167 .012363540000000001 3 1
      "126554" "01" 16076 "A" "AGILENT TECHNOLOGIES INC" 1 30.48 1 29.55 1 1 30.48 29.55 .03147209 .00152753 3 1
      "126554" "01" 16077 "A" "AGILENT TECHNOLOGIES INC" 1 30.87 1 30.48 1 1 30.87 30.48 .012795318 .002584864 3 1
      "126554" "01" 16078 "A" "AGILENT TECHNOLOGIES INC" 1 32.28 1 30.87 1 1 32.28 30.87 .04567534 .004678675 3 1
      "126554" "01" 16079 "A" "AGILENT TECHNOLOGIES INC" 1 32.05 1 32.28 1 1 32.05 32.28 -.007125141 -.008474771 3 1
      "126554" "01" 16082 "A" "AGILENT TECHNOLOGIES INC" 1 32.4 1 32.05 1 1 32.4 32.05 .01092051 .004793193 3 1
      "126554" "01" 16083 "A" "AGILENT TECHNOLOGIES INC" 1 32.24 1 32.4 1 1 32.24 32.4 -.004938267 -.005393305 3 1
      "126554" "01" 16084 "A" "AGILENT TECHNOLOGIES INC" 1 32.14 1 32.24 1 1 32.14 32.24 -.003101808 .008277668 3 1
      "126554" "01" 16085 "A" "AGILENT TECHNOLOGIES INC" 1 32.91 1 32.14 1 1 32.91 32.14 .0239577 .001494761 3 1
      "126554" "01" 16086 "A" "AGILENT TECHNOLOGIES INC" 1 34.25 1 32.91 1 1 34.25 32.91 .04071711 .006693901 3 1
      "126554" "01" 16090 "A" "AGILENT TECHNOLOGIES INC" 1 34.01 1 34.25 1 1 34.01 34.25 -.007007348 -.0005250069 3 1
      "126554" "01" 16091 "A" "AGILENT TECHNOLOGIES INC" 1 34.77 1 34.01 1 1 34.77 34.01 .022346433 .00764944 3 1
      "126554" "01" 16092 "A" "AGILENT TECHNOLOGIES INC" 1 33.98 1 34.77 1 1 33.98 34.77 -.02272076 -.00303623 3 1
      "126554" "01" 16093 "A" "AGILENT TECHNOLOGIES INC" 1 33.44 1 33.98 1 1 33.44 33.98 -.015891729 -.002350528 3 1
      "126554" "01" 16096 "A" "AGILENT TECHNOLOGIES INC" 1 33.91 1 33.44 1 1 33.91 33.44 .01405506 .01217783 3 1
      "126554" "01" 16097 "A" "AGILENT TECHNOLOGIES INC" 1 36.1 1 33.91 1 1 36.1 33.91 .064582676 -.009620705 3 1
      "126554" "01" 16098 "A" "AGILENT TECHNOLOGIES INC" 1 35.95 1 36.1 1 1 35.95 36.1 -.004155061 -.013277220000000001 3 1
      "126554" "01" 16099 "A" "AGILENT TECHNOLOGIES INC" 1 35.65 1 35.95 1 1 35.65 35.95 -.008344902 .0050159160000000005 3 1
      "126554" "01" 16100 "A" "AGILENT TECHNOLOGIES INC" 1 36.86 1 35.65 1 1 36.86 35.65 .033941068 -.002478133 3 1
      "126554" "01" 16103 "A" "AGILENT TECHNOLOGIES INC" 1 36.42 1 36.86 1 1 36.42 36.86 -.011937126 .003639798 3 1
      "126554" "01" 16104 "A" "AGILENT TECHNOLOGIES INC" 1 36.48 1 36.42 1 1 36.48 36.42 .0016474843 .0006138779000000001 3 1
      "126554" "01" 16105 "A" "AGILENT TECHNOLOGIES INC" 1 35.3 1 36.48 1 1 35.3 36.48 -.0323465 -.008127442 3 1
      "126554" "01" 16106 "A" "AGILENT TECHNOLOGIES INC" 1 35.23 1 35.3 1 1 35.23 35.3 -.0019829941 .002054057 3 1
      "126554" "01" 16107 "A" "AGILENT TECHNOLOGIES INC" 1 36.85 1 35.23 1 1 36.85 35.23 .04598351 .0124336 3 1
      "126554" "01" 16110 "A" "AGILENT TECHNOLOGIES INC" 1 37.1 1 36.85 1 1 37.1 36.85 .006784261 -.0022863690000000003 3 1
      "126554" "01" 16111 "A" "AGILENT TECHNOLOGIES INC" 1 37.37 1 37.1 1 1 37.37 37.1 .00727764 .004840428 3 1
      "126554" "01" 16112 "A" "AGILENT TECHNOLOGIES INC" 1 37.4 1 37.37 1 1 37.4 37.37 .0008028524 .01136784 3 1
      "126554" "01" 16113 "A" "AGILENT TECHNOLOGIES INC" 1 36.92 1 37.4 1 1 36.92 37.4 -.012834314 -.0046011820000000005 3 1
      "126554" "01" 16114 "A" "AGILENT TECHNOLOGIES INC" 1 37.08 1 36.92 1 1 37.08 36.92 .0043337937 -.005269152 3 1
      "126554" "01" 16118 "A" "AGILENT TECHNOLOGIES INC" 1 37.49 1 37.08 1 1 37.49 37.08 .01105717 .009677953000000001 3 1
      "126554" "01" 16119 "A" "AGILENT TECHNOLOGIES INC" 1 35.98 1 37.49 1 1 35.98 37.49 -.04027746 -.004407357000000001 3 1
      "126554" "01" 16120 "A" "AGILENT TECHNOLOGIES INC" 1 36.09 1 35.98 1 1 36.09 35.98 .003057271 -.003956661 3 1
      "126554" "01" 16121 "A" "AGILENT TECHNOLOGIES INC" 1 35.05 1 36.09 1 1 35.05 36.09 -.02881687 -.0025001980000000004 3 1
      "126554" "01" 16124 "A" "AGILENT TECHNOLOGIES INC" 1 33.72 1 35.05 1 1 33.72 35.05 -.03794574 -.0028701 3 1
      "126554" "01" 16125 "A" "AGILENT TECHNOLOGIES INC" 1 33.75 1 33.72 1 1 33.75 33.72 .0008896435 -.0015135370000000001 3 1
      "126554" "01" 16126 "A" "AGILENT TECHNOLOGIES INC" 1 33.95 1 33.75 1 1 33.95 33.75 .005925949 .004259853 3 1
      "126554" "01" 16127 "A" "AGILENT TECHNOLOGIES INC" 1 34.2 1 33.95 1 1 34.2 33.95 .00736377 .001236883 3 1
      "126554" "01" 16128 "A" "AGILENT TECHNOLOGIES INC" 1 34.19 1 34.2 1 1 34.19 34.2 -.0002924601 -.00002356882 3 1
      "126554" "01" 16131 "A" "AGILENT TECHNOLOGIES INC" 1 34.33 1 34.19 1 1 34.33 34.19 .0040948587 .009762057000000001 3 1
      "126554" "01" 16132 "A" "AGILENT TECHNOLOGIES INC" 1 34.23 1 34.33 1 1 34.23 34.33 -.002912971 -.005751784 3 1
      "126554" "01" 16133 "A" "AGILENT TECHNOLOGIES INC" 1 33.97 1 34.23 1 1 33.97 34.23 -.007595628 .0019186320000000002 3 1
      "126554" "01" 16134 "A" "AGILENT TECHNOLOGIES INC" 1 33.95 1 33.97 1 1 33.95 33.97 -.0005887682 .003157155 3 1
      "126554" "01" 16135 "A" "AGILENT TECHNOLOGIES INC" 1 34.81 1 33.95 1 1 34.81 33.95 .02533139 .001925519 3 1
      "126554" "01" 16138 "A" "AGILENT TECHNOLOGIES INC" 1 33.62 1 34.81 1 1 33.62 34.81 -.034185648 -.008260261000000001 3 1
      "126554" "01" 16139 "A" "AGILENT TECHNOLOGIES INC" 1 32.83 1 33.62 1 1 32.83 33.62 -.023497833 -.0057208250000000006 3 1
      "126554" "01" 16140 "A" "AGILENT TECHNOLOGIES INC" 1 31.56 1 32.83 1 1 31.56 32.83 -.0386842 -.01467895 3 1
      "126554" "01" 16141 "A" "AGILENT TECHNOLOGIES INC" 1 30.2 1 31.56 1 1 30.2 31.56 -.04309248 -.014917670000000001 3 1
      "126554" "01" 16142 "A" "AGILENT TECHNOLOGIES INC" 1 31.65 1 30.2 1 1 31.65 30.2 .04801321 .01232232 3 1
      "126554" "01" 16145 "A" "AGILENT TECHNOLOGIES INC" 1 30.27 1 31.65 1 1 30.27 31.65 -.04360187 -.01422952 3 1
      "126554" "01" 16146 "A" "AGILENT TECHNOLOGIES INC" 1 30.19 1 30.27 1 1 30.19 30.27 -.002642878 .005729892 3 1
      "126554" "01" 16147 "A" "AGILENT TECHNOLOGIES INC" 1 31.63 1 30.19 1 1 31.63 30.19 .04769787 .01172893 3 1
      "126554" "01" 16148 "A" "AGILENT TECHNOLOGIES INC" 1 30.6 1 31.63 1 1 30.6 31.63 -.032563984 -.0012034580000000001 3 1
      "126554" "01" 16149 "A" "AGILENT TECHNOLOGIES INC" 1 30.55 1 30.6 1 1 30.55 30.6 -.0016340243 -.01119961 3 1
      "126554" "01" 16152 "A" "AGILENT TECHNOLOGIES INC" 1 30.16 1 30.55 1 1 30.16 30.55 -.012765937 -.01304785 3 1
      "126554" "01" 16153 "A" "AGILENT TECHNOLOGIES INC" 1 28.9 1 30.16 1 1 28.9 30.16 -.0417772 -.001155877 3 1
      "126554" "01" 16154 "A" "AGILENT TECHNOLOGIES INC" 1 29.27 1 28.9 1 1 29.27 28.9 .012802797 -.002434325 3 1
      "126554" "01" 16155 "A" "AGILENT TECHNOLOGIES INC" 1 30.7 1 29.27 1 1 30.7 29.27 .0488555 .01620477 3 1
      "126554" "01" 16156 "A" "AGILENT TECHNOLOGIES INC" 1 30.79 1 30.7 1 1 30.79 30.7 .002931601 -.0008148826 3 1
      "126554" "01" 16159 "A" "AGILENT TECHNOLOGIES INC" 1 31.27 1 30.79 1 1 31.27 30.79 .015589462 .0131321 3 1
      "126554" "01" 16160 "A" "AGILENT TECHNOLOGIES INC" 1 31.46 1 31.27 1 1 31.46 31.27 .006076067 .004022497 3 1
      "126554" "01" 16161 "A" "AGILENT TECHNOLOGIES INC" 1 31.63 1 31.46 1 1 31.63 31.46 .00540369 -.0006585676 3 1
      "126554" "01" 16162 "A" "AGILENT TECHNOLOGIES INC" 1 31.64 1 31.63 1 1 31.64 31.63 .0003161628 .005424041 3 1
      "126554" "01" 16163 "A" "AGILENT TECHNOLOGIES INC" 1 32.32 1 31.64 1 1 32.32 31.64 .02149179 .008511707 3 1
      "126554" "01" 16166 "A" "AGILENT TECHNOLOGIES INC" 1 32.44 1 32.32 1 1 32.44 32.32 .003712838 .007584156000000001 3 1
      "126554" "01" 16167 "A" "AGILENT TECHNOLOGIES INC" 1 32.56 1 32.44 1 1 32.56 32.44 .0036992216 -.0018345330000000002 3 1
      "126554" "01" 16168 "A" "AGILENT TECHNOLOGIES INC" 1 31.86 1 32.56 1 1 31.86 32.56 -.021498794 -.006451489 3 1
      "126554" "01" 16169 "A" "AGILENT TECHNOLOGIES INC" 1 31.83 1 31.86 1 1 31.83 31.86 -.0009416411 -.001078049 3 1
      "126554" "01" 16173 "A" "AGILENT TECHNOLOGIES INC" 1 31.87 1 31.83 1 1 31.87 31.83 .001256705 .005075228 3 1
      "126554" "01" 16174 "A" "AGILENT TECHNOLOGIES INC" 1 31.01 1 31.87 1 1 31.01 31.87 -.026984643 -.01371705 3 1
      "126554" "01" 16175 "A" "AGILENT TECHNOLOGIES INC" 1 30.76 1 31.01 1 1 30.76 31.01 -.008061916 -.001355448 3 1
      "126554" "01" 16176 "A" "AGILENT TECHNOLOGIES INC" 1 29.9 1 30.76 1 1 29.9 30.76 -.02795841 .0007720384 3 1
      "126554" "01" 16177 "A" "AGILENT TECHNOLOGIES INC" 1 30.13 1 29.9 1 1 30.13 29.9 .007692292 .005127538 3 1
      "126554" "01" 16180 "A" "AGILENT TECHNOLOGIES INC" 1 30.4 1 30.13 1 1 30.4 30.13 .008961184 .0009791838 3 1
      "126554" "01" 16181 "A" "AGILENT TECHNOLOGIES INC" 1 28.74 1 30.4 1 1 28.74 30.4 -.05460526 -.015487530000000001 3 1
      "126554" "01" 16182 "A" "AGILENT TECHNOLOGIES INC" 1 29.04 1 28.74 1 1 29.04 28.74 .010438453 .00539987 3 1
      "126554" "01" 16183 "A" "AGILENT TECHNOLOGIES INC" 1 29.37 1 29.04 1 1 29.37 29.04 .011363633 .01415273 3 1
      "126554" "01" 16184 "A" "AGILENT TECHNOLOGIES INC" 1 29.5 1 29.37 1 1 29.5 29.37 .0044262568 .00045723140000000003 3 1
      "126554" "01" 16187 "A" "AGILENT TECHNOLOGIES INC" 1 29.09 1 29.5 1 1 29.09 29.5 -.0138983 -.004326843 3 1
      "126554" "01" 16188 "A" "AGILENT TECHNOLOGIES INC" 1 28.81 1 29.09 1 1 28.81 29.09 -.009625324 .0022773980000000004 3 1
      "126554" "01" 16189 "A" "AGILENT TECHNOLOGIES INC" 1 28.3 1 28.81 1 1 28.3 28.81 -.017702196 -.013859940000000001 3 1
      "126554" "01" 16190 "A" "AGILENT TECHNOLOGIES INC" 1 27.8 1 28.3 1 1 27.8 28.3 -.017667845 -.0072028610000000005 3 1
      "126554" "01" 16191 "A" "AGILENT TECHNOLOGIES INC" 1 27.01 1 27.8 1 1 27.01 27.8 -.02841723 -.005700935000000001 3 1
      "126554" "01" 16194 "A" "AGILENT TECHNOLOGIES INC" 1 27.26 1 27.01 1 1 27.26 27.01 .009255831 .009064674 3 1
      "126554" "01" 16195 "A" "AGILENT TECHNOLOGIES INC" 1 26.73 1 27.26 1 1 26.73 27.26 -.01944243 .00195443 3 1
      "126554" "01" 16196 "A" "AGILENT TECHNOLOGIES INC" 1 26.81 1 26.73 1 1 26.81 26.73 .002992889 .001962253 3 1
      "126554" "01" 16197 "A" "AGILENT TECHNOLOGIES INC" 1 26.34 1 26.81 1 1 26.34 26.81 -.017530747 -.006614263 3 1
      "126554" "01" 16198 "A" "AGILENT TECHNOLOGIES INC" 1 26.31 1 26.34 1 1 26.31 26.34 -.0011389782 -.0137994 3 1
      "126554" "01" 16201 "A" "AGILENT TECHNOLOGIES INC" 1 25.41 1 26.31 1 1 25.41 26.31 -.03420751 -.0104501 3 1
      "126554" "01" 16202 "A" "AGILENT TECHNOLOGIES INC" 1 26.2 1 25.41 1 1 26.2 25.41 .03109016 .007734124 3 1
      "126554" "01" 16203 "A" "AGILENT TECHNOLOGIES INC" 1 26.16 1 26.2 1 1 26.16 26.2 -.0015267525 .002159827 3 1
      "126554" "01" 16204 "A" "AGILENT TECHNOLOGIES INC" 1 26.02 1 26.16 1 1 26.02 26.16 -.005351658 -.0007277736 3 1
      "126554" "01" 16205 "A" "AGILENT TECHNOLOGIES INC" 1 25.59 1 26.02 1 1 25.59 26.02 -.01652576 -.000652116 3 1
      "126554" "01" 16208 "A" "AGILENT TECHNOLOGIES INC" 1 25.52 1 25.59 1 1 25.52 25.59 -.0027354315 -.01045764 3 1
      "126554" "01" 16209 "A" "AGILENT TECHNOLOGIES INC" 1 25.4 1 25.52 1 1 25.4 25.52 -.004702227 .006922429000000001 3 1
      "126554" "01" 16210 "A" "AGILENT TECHNOLOGIES INC" 1 25.21 1 25.4 1 1 25.21 25.4 -.007480336 -.0024060320000000002 3 1
      "126554" "01" 16211 "A" "AGILENT TECHNOLOGIES INC" 1 24.3 1 25.21 1 1 24.3 25.21 -.03609678 .00042903280000000004 3 1
      "126554" "01" 16212 "A" "AGILENT TECHNOLOGIES INC" 1 24.38 1 24.3 1 1 24.38 24.3 .003292178 .004088612 3 1
      "126554" "01" 16215 "A" "AGILENT TECHNOLOGIES INC" 1 24.35 1 24.38 1 1 24.35 24.38 -.0012304668 .0016453610000000001 3 1
      "126554" "01" 16216 "A" "AGILENT TECHNOLOGIES INC" 1 24.73 1 24.35 1 1 24.73 24.35 .015605715 .0160073 3 1
      end
      format %td datadate
      label values _merge _merge
      label def _merge 3 "Matched (3)", modify
      label values tic_1 tic_1
      label def tic_1 1 "A", modify

      Comment


      • #63
        First, -verbose- is not a command. It is an option you can specify in the -runby- command that causes it to show, rather than suppress, the output of program one_day.

        Now, looking more carefully at program one_day, there are a number of errors. A corrected version of it is shown here:

        Code:
        capture program drop one_day
        program define one_day
            tsset tic_1 datadate, daily
            summ ValueWeightedReturnincldivi
            local denom = r(Var)
            corr daily_tot_return ValueWeightedReturnincldivi, cov
            local nom = r(cov_12)
            // corr command deleted here as it is a repeat and its results are never used
            gen beta = `nom'/`denom'
            exit
        end
        Now that I see your example data, there is a conceptual error in your use of -runby-. At least in your example data (and since you say you have panel data, this is probably true of your full data set as well) the combination of tic_1 and datadate (which, in addition, you mistyped with a spurious space between data and date, and with an illegal comma after tic_1), uniquely identifies observations. So each combination of tic_1 and datadate corresponds only to a single observation. And with only one observation you cannot calculate any correlations or covariances. I think you meant to do either -by(tic_1)- or -by(datedate)-, but I have no idea which.

        Comment


        • #64
          Thank you so so much for your help!! The corrected version works. The only problem I have now ist that the -runby- does not work, beause I initially wanted to calculate the beta factor based on the tic_1 and the datadate variable. Now, I receive the same value for the individual tic_1 values which is not correct. Do you know what is incorrect here?

          Comment


          • #65
            beause I initially wanted to calculate the beta factor based on the tic_1 and the datadate variable.
            Well, you need another plan. If your beta factor is a regression coefficient or based on correlations, given that for each combination of tic_1 and datadate there is only one observation, then it is not possible. You cannot do a correlation, covariance, or regression on a single observation.

            I do not know if the problem is that your data is wrong, and there should be multiple observations for each combination of tic_1 and datadate, or if you don't understand what you're trying to do. In any case, the problem is not with the Stata code at this point. The problem is either with your data or with your research plan. Either way, you need advice from somebody who is familiar with the subject matter you are trying to study. Try consulting with a colleague in your field, or reviewing the literature to see how other people have approached this problem or highly similar ones.

            Comment

            Working...
            X