Announcement

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

  • #31
    You don't need to generate a year variable. You already have one in date3. This is evident from your own listing.

    Moreover, date2 is just the day of the month 1 to 31 and not at all a daily date. This is also evident from your own listing.

    yofd(date2) will just map date2 interpreted as daily dates into a year, and as all the daily dates are no greater than 31, all the results are in (January) 1960, and so the year is returned as 1960, always, which is nonsense. In your data example it should clearly be 2006.

    Reading

    Code:
    help datetime
    is essential to understand how dates are handled in Stata

    Conversely, I can't follow why it is interesting or useful to calculate the logit of R-square.

    Comment


    • #32
      Re #30: Yes, you can get what you're looking for by -merge-ing regression_resultsa back to the original data set.

      But the whole approach you are taking is unnecessarily complicated. The following code will do it more simply, and, if your data set is appreciably large, noticeably faster:

      Code:
      rangestat (reg) firm_return market_return, by(firm_id) interval(date3 0 0)
      -rangestat- is written by Robert Picard, Nick Cox, and Roberto Ferrer and is available from SSC.
      If the coefficients and standard errors and adjusted r2 are of no interest to you, you can drop them.

      In #30, Nick Cox has explained how best to manage your date variable. The code above uses your variable date3 to represent the year, as it is already there in the example data.

      Comment


      • #33
        Dear all,

        First of all i am very thankful to Nick Cox ​​​Clyde Schechter for your suggestions and guidance,i will read the datetime commands in detail.
        the rangestat command is very comprehensive and very easy to calculate the R2 as compared to my previous one, thank you once again sir for your's time.
        I just want to ask some other questions, if i want to convert this daily data to weekly data , and also to takes leads and lags of market return , then how i can convert my daily data to weekly data (5 trading days i.e Monday to Friday) and to regress the firm‘s weekly returns on current, lead and lagged market return
        Q1 I am facing problem in converting days to week,below command consider 7 days a week and can start from any working days,although my dataset is maximum 5 trading days in a week, Q2 second i want to consider 5 days a week

        Code:
        gen date=date("1/4/2006" , "MDY")+_n  
              format %td date      
              tsset date
        ascol  firm_returnit  , toweek returns(simple) keep(all) .
        ascol  market_return  , toweek returns(simple) keep(all)
        sort firm_id week_id
        Code:
         * Example generated by -dataex-. To install: ssc install dataex clear input long firm_id str10 trddt byte(date1 date2) int date3 float(date week_id) double week_firm_return float week_id_000 double week_market_return
        2 "1/4/2006"  1  4 2006 16806 2392   .08816697903496751 2392 .04941479535130733
        2 "1/5/2006"  1  5 2006 16807 2392   .08816697903496751 2392 .04941479535130733
        2 "1/6/2006"  1  6 2006 16808 2392   .08816697903496751 2392 .04941479535130733
        2 "1/9/2006"  1  9 2006 16809 2393 -.053304778928444874 2393 .01919176673582368
        2 "1/10/2006" 1 10 2006 16810 2393 -.053304778928444874 2393 .01919176673582368
        2 "1/11/2006" 1 11 2006 16811 2393 -.053304778928444874 2393 .01919176673582368
        2 "1/12/2006" 1 12 2006 16812 2393 -.053304778928444874 2393 .01919176673582368
        2 "1/13/2006" 1 13 2006 16813 2393 -.053304778928444874 2393 .01919176673582368
        2 "1/16/2006" 1 16 2006 16814 2393 -.053304778928444874 2393 .01919176673582368
        2 "1/17/2006" 1 17 2006 16815 2393 -.053304778928444874 2393 .01919176673582368
        2 "1/18/2006" 1 18 2006 16816 2394   .20945930434477122 2394 .07530722870489903
        2 "1/19/2006" 1 19 2006 16817 2394   .20945930434477122 2394 .07530722870489903
        2 "1/20/2006" 1 20 2006 16818 2394   .20945930434477122 2394 .07530722870489903
        2 "1/23/2006" 1 23 2006 16819 2394   .20945930434477122 2394 .07530722870489903
        2 "1/24/2006" 1 24 2006 16820 2394   .20945930434477122 2394 .07530722870489903
        2 "1/25/2006" 1 25 2006 16821 2394   .20945930434477122 2394 .07530722870489903
        2 "2/6/2006"  2  6 2006 16822 2394   .20945930434477122 2394 .07530722870489903
        2 "2/7/2006"  2  7 2006 16823 2395  .026072095408721685 2395 .01954018422906456
        2 "2/8/2006"  2  8 2006 16824 2395  .026072095408721685 2395 .01954018422906456
        2 "2/9/2006"  2  9 2006 16825 2395  .026072095408721685 2395 .01954018422906456
        end format %td date format %tw week_id format %tw week_id_000
        Code:
         * Example generated by -dataex-. To install: ssc install dataex clear input long firm_id float(firm_return market_return date week_id) double week_firm_return float week_id_000 double week_market_return float(market_return_lead1 market_return_lead2 market_return_lag1 market_return_lag2)
        2  .081206  .018919 16806 2392    .08816697903496751 2392    .04941479535130733   .019191766    .07530723            .            .
        2 -.012793  .011173 16809 2393  -.053304778928444874 2393    .01919176673582368    .07530723   .019540185     .0494148            .
        2  .022523  .020927 16816 2394    .20945930434477122 2394    .07530722870489903   .019540185  .0017963736   .019191766     .0494148
        2 -.022346  .001814 16823 2395   .026072095408721685 2395    .01954018422906456  .0017963736   -.04501196    .07530723   .019191766
        2 -.025408 -.028821 16830 2396    .01814967061651318 2396   .001796373674310292   -.04501196   .017853292   .019540185    .07530723
        2 -.033868 -.006814 16837 2397   -.07486546126360061 2397   -.04501195689839976   .017853292    .04448462  .0017963736   .019540185
        2 -.026975 -.008139 16844 2398    .06358403574336036 2398   .017853291417061268    .04448462    .05897206   -.04501196  .0017963736
        2  -.01087 -.004058 16851 2399    .13043459917790567 2399    .04448461840287932    .05897206    .04844668   .017853292   -.04501196
        2  .043269  .009792 16858 2400    .11858935179683416 2400    .05897206184403103    .04844668 -.0006621344    .04448462   .017853292
        2 -.001433  .008904 16865 2401  -.054442288604951594 2401    .04844668270768837 -.0006621344    .13799173    .05897206    .04448462
         end format %td date format %tw week_id format %tw week_id_000
        Q3.Third i have some missing values because of lags and lead market value so interval( week_id 0 0) give me below message ,
        no result for all obs: reg week_firm_return market_return_lag2 market_return_lag1 week_market_return market_return_l > ead1 market_return_lead2
        but if i replaced it with interval( week_id . .) then i can get values,but i am not sure is it the correct command to replace 0 0 with . . in interval Q4.How can i drop observation if total weeks are less than 40 in a year.i mean 200 trading days Looking forward for yours cooperation.
        Last edited by Ayub UOM; 13 Sep 2019, 23:34.

        Comment


        • #34
          Thanks for your dataex output, mangled but manageable.

          First off, your new variable

          Code:
          gen date=date("1/4/2006" , "MDY")+_n
          ignores gaps in the data and is thus incorrect after the first gap. ascol (SSC, as you are asked to explain) I don't know about but it can't correct an incorrect variable. I can't see where your week_id comes from, but it's wrong too. On no definition are 1/10/2006 and 1/17/2006 in the same week. Weeks are tricky in Stata but the key for you is that dow() yields 1 for Mondays .... 5 for Fridays. That being so, you are best off indexing each week by the Monday that starts it. Here is some technique.
          Code:
           * Example generated by -dataex-. To install: ssc install dataex clear input str10 trddt "1/4/2006"  "1/5/2006"  "1/6/2006"  "1/9/2006"  "1/10/2006" "1/11/2006" "1/12/2006" "1/13/2006" "1/16/2006" "1/17/2006" "1/18/2006" "1/19/2006" "1/20/2006" "1/23/2006" "1/24/2006" "1/25/2006" "2/6/2006"  "2/7/2006"  "2/8/2006"  "2/9/2006"  end  gen betterdate = daily(trddt, "MDY") format betterdate %td gen dow = dow(betterdate) gen weekdate = betterdate - dow + 1 format weekdate %td  l trddt betterdate dow weekdate, sepby(weekdate)       +-----------------------------------------+      |     trddt   betterd~e   dow    weekdate |      |-----------------------------------------|   1. |  1/4/2006   04jan2006     3   02jan2006 |   2. |  1/5/2006   05jan2006     4   02jan2006 |   3. |  1/6/2006   06jan2006     5   02jan2006 |      |-----------------------------------------|   4. |  1/9/2006   09jan2006     1   09jan2006 |   5. | 1/10/2006   10jan2006     2   09jan2006 |   6. | 1/11/2006   11jan2006     3   09jan2006 |   7. | 1/12/2006   12jan2006     4   09jan2006 |   8. | 1/13/2006   13jan2006     5   09jan2006 |      |-----------------------------------------|   9. | 1/16/2006   16jan2006     1   16jan2006 |  10. | 1/17/2006   17jan2006     2   16jan2006 |  11. | 1/18/2006   18jan2006     3   16jan2006 |  12. | 1/19/2006   19jan2006     4   16jan2006 |  13. | 1/20/2006   20jan2006     5   16jan2006 |      |-----------------------------------------|  14. | 1/23/2006   23jan2006     1   23jan2006 |  15. | 1/24/2006   24jan2006     2   23jan2006 |  16. | 1/25/2006   25jan2006     3   23jan2006 |      |-----------------------------------------|  17. |  2/6/2006   06feb2006     1   06feb2006 |  18. |  2/7/2006   07feb2006     2   06feb2006 |  19. |  2/8/2006   08feb2006     3   06feb2006 |  20. |  2/9/2006   09feb2006     4   06feb2006 |      +-----------------------------------------+
          For much more on Stata weeks, see
          Code:
           . search weekly, sj  Search of official help files, FAQs, Examples, SJs, and STBs  SJ-12-4 dm0065_1  . . . . . Stata tip 111: More on working with weeks, erratum         . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox         Q4/12   SJ 12(4):765                                     (no commands)         lists previously omitted key reference  SJ-12-3 dm0065  . . . . . . . . . .  Stata tip 111: More on working with weeks         . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox         Q3/12   SJ 12(3):565--569                                (no commands)         discusses how to convert data presented in yearly and weekly         form to daily dates and how to aggregate such data to months         or longer intervals  SJ-10-4 dm0052  . . . . . . . . . . . . . . . . Stata tip 68: Week assumptions         . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox         Q4/10   SJ 10(4):682--685                                (no commands)         tip on Stata's solution for weeks and on how to set up         your own alternatives given different definitions of the         week
          -- noting that typing
          Code:
          search weekly, sj
          in Stata will give you clickable links. Stata's own definition of weeks is not what you want here.

          Comment


          • #35
            That got mangled too. Let's try again:


            Code:
            * Example generated by -dataex-. To install: ssc install dataex
            clear
            input str10 trddt
            "1/4/2006" 
            "1/5/2006" 
            "1/6/2006" 
            "1/9/2006" 
            "1/10/2006"
            "1/11/2006"
            "1/12/2006"
            "1/13/2006"
            "1/16/2006"
            "1/17/2006"
            "1/18/2006"
            "1/19/2006"
            "1/20/2006"
            "1/23/2006"
            "1/24/2006"
            "1/25/2006"
            "2/6/2006" 
            "2/7/2006" 
            "2/8/2006" 
            "2/9/2006" 
            end
            
            gen betterdate = daily(trddt, "MDY")
            
            format betterdate %td
            
            gen dow = dow(betterdate)
            
            gen weekdate = betterdate - dow + 1
            
            format weekdate %td
            
            list trddt betterdate dow weekdate, sepby(weekdate)
            
                 +-----------------------------------------+
                 |     trddt   betterd~e   dow    weekdate |
                 |-----------------------------------------|
              1. |  1/4/2006   04jan2006     3   02jan2006 |
              2. |  1/5/2006   05jan2006     4   02jan2006 |
              3. |  1/6/2006   06jan2006     5   02jan2006 |
                 |-----------------------------------------|
              4. |  1/9/2006   09jan2006     1   09jan2006 |
              5. | 1/10/2006   10jan2006     2   09jan2006 |
              6. | 1/11/2006   11jan2006     3   09jan2006 |
              7. | 1/12/2006   12jan2006     4   09jan2006 |
              8. | 1/13/2006   13jan2006     5   09jan2006 |
                 |-----------------------------------------|
              9. | 1/16/2006   16jan2006     1   16jan2006 |
             10. | 1/17/2006   17jan2006     2   16jan2006 |
             11. | 1/18/2006   18jan2006     3   16jan2006 |
             12. | 1/19/2006   19jan2006     4   16jan2006 |
             13. | 1/20/2006   20jan2006     5   16jan2006 |
                 |-----------------------------------------|
             14. | 1/23/2006   23jan2006     1   23jan2006 |
             15. | 1/24/2006   24jan2006     2   23jan2006 |
             16. | 1/25/2006   25jan2006     3   23jan2006 |
                 |-----------------------------------------|
             17. |  2/6/2006   06feb2006     1   06feb2006 |
             18. |  2/7/2006   07feb2006     2   06feb2006 |
             19. |  2/8/2006   08feb2006     3   06feb2006 |
             20. |  2/9/2006   09feb2006     4   06feb2006 |
                 +-----------------------------------------+
            Code:
             
            . search weekly, sj
            
            Search of official help files, FAQs, Examples, SJs, and STBs
            
            SJ-12-4 dm0065_1  . . . . . Stata tip 111: More on working with weeks, erratum
                    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
                    Q4/12   SJ 12(4):765                                     (no commands)
                    lists previously omitted key reference
            
            SJ-12-3 dm0065  . . . . . . . . . .  Stata tip 111: More on working with weeks
                    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
                    Q3/12   SJ 12(3):565--569                                (no commands)
                    discusses how to convert data presented in yearly and weekly
                    form to daily dates and how to aggregate such data to months
                    or longer intervals
            
            SJ-10-4 dm0052  . . . . . . . . . . . . . . . . Stata tip 68: Week assumptions
                    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
                    Q4/10   SJ 10(4):682--685                                (no commands)
                    tip on Stata's solution for weeks and on how to set up
                    your own alternatives given different definitions of the
                    week

            Comment


            • #36
              Nick Cox
              Thank you so much, sir, for your very quick replay and kindness,although i tried to manage the dataex output,
              mangled but manageable.
              but after uploading the post, unfortunately, its format changed. initially I tried to upload1/50 observation. but later i dropped maximum and maybe that's the main problem my data was not in a proper form, so sorry for that and thanks for your time once again to manage raw-data into an organized form for me.
              second i was thinking about the proper definition of the weekend i wrote a question that i want to manage my week date from Monday to Friday 1 to 5. but later on I deleted that question because i was thinking maybe this is Silly question. But i really appreciate your competency and commands on how to ask a question from a student and then how to answer it as well , so once again i am very thankful for sharing different links with me to read about it in detail.
              So far i run yous codes and everything is fine, i will try tomorrow to run all of my commands, so if i need further help i will request for that again.
              Best regards

              Comment


              • #37
                Hello statalist members,
                I want to merge two files of my weekely data, but i don't know how to format my date variable trdwnt in to this format
                2002w1 2002w2 ....2002w52
                format,
                so that i can merge both file by same yearweek variable,
                although i have used this method to first destring and split trdwnt variable and then
                Code:
                egen dategroup=group( year week)
                but it assign i uniques number to every firm in same year and same week and different number, if year or week is changing, i want to merge my both file by dategroup, but I think maybe its not a proper way to do my task, therefore i want to use a proper format for yearweek date


                Code:
                * Example generated by -dataex-. To install: ssc install dataex
                clear
                input long code str7 trdwnt int year byte week
                600664 "2002-01" 2002 1
                600319 "2002-02" 2002 2
                600225 "2002-03" 2002 3
                600866 "2002-04" 2002 4
                600750 "2002-06" 2002 6
                600665 "2002-52" 2002 52
                
                end
                could you please guide me about the correct method for merging tow different files , having very few common variables and one file has more observations and others are just in few hundreds, and also about the format for year-week and year_month from the above string variable,.
                last time @ Nick cox tolde me about date format and coding but it was very helpful for YMD and i am not succeeded to deal with YM or YW format.
                best regards

                Comment


                • #38
                  Please look again at the title for the thread: this is drifting away from it. You'd be better off re-posting this in a new thread with some title like "Handling weekly data" and providing a cross-reference to that thread in this (and to this thread in that).

                  In #34, parts better presented as #35, I gave explicit advice

                  Stata's own definition of weeks is not what you want here.

                  and that's still my advice. The implication of #37 is that you've not read or not understood the articles cited earlier.

                  Now in #37 you are showing us data from somewhere. If the data source is using Stata's definition of weeks, that's one thing, but I have never heard of any data provider doing that. Conversely, no worthwhile advice is possible on handling those data unless you tell us the definition of week being used.

                  Comment


                  • #39
                    Nick Cox
                    sorry sir for not starting a new thread earlier, i have created a new thread reference herewith
                    https://www.statalist.org/forums/for...ng-weekly-data
                    and i will further discuss this issue there.
                    Nick i readed those materials you referred to me, but my be my understanding level is not so much good,therefore i posted here for clarification,and the date format was also little bit different than "MDY" and its already weekly data,so i think the definition of week will be the same just like Stata's definition of weeks.
                    Thank you again for your nice suggestion to post a relevant question in a relevant place.

                    Comment


                    • #40
                      Hello statalist members,
                      sorry for asking these questions,i am litle bit confused about some points, therefore i want to clarify my concept.i am trying to calculate SYNCH for firm i in year t = Log(R2/1-R2). and also to calculate industry weekly return.
                      my data set is based on weekly observations on each firm.could you please guide me about these questions?

                      Q1.what is the difference between these two commands, in the first case (#11) , only 600 observation are dropped from my dataset

                      Code:
                       egen zero_return_weeks = total(weekly_return == 0), by(firm_id year) drop if zero_return_weeks >= 7
                      but when i am using command in # 15 then 787608 observation is dropped from my data set out of total 17 lac,so what is the reason behind this

                      Code:
                          
                       //  EXCLUDE FIRMS WITH 0 RETURN FOR 7 OR MORE WEEKS by firm_id, sort: egen weeks_of_zero_return = total(weekly_return == 0) drop if weeks_of_zero_return > 7
                      Q2: in # 15 and in # 17 i don't know how to generate total_industry_return ,so can i take total_industry_return = industry_mv ?

                      Q3: can i replace # 17 with #32 command ? if yes then how can i make some changes in by(firm_id year) or only by(firm_id )
                      Code:
                       statsby e(r2_o), by(firm_id year) saving(r2_by_firm_by_year, replace): ///     xtreg weekly_return weekly_market_return L1.weekly_market_return ///     weighted_mean_industry_return L1.weighted_mean_industry_return

                      Code:
                       rangestat (reg) weekly_return weekly_market_return L1.weekly_market_return weighted_mean_industry_return L1.weighted_mean_industry_return, by(firm_id) interval(date3 0 0)  
                       rangestat (reg) weekly_return weekly_market_return L1.weekly_market_return weighted_mean_industry_return L1.weighted_mean_industry_return, by(firm_id year) interval(date3 0 0)
                      Q4:
                      in # 18 and #19 i am also facing same problem, so can i solve this problem if i am using rangestat command and to delete those observations in comment columns where insufficient observation message is written

                      Q5:in # 6 and #9 for year variable this command is used
                      Code:
                       gen year = yofd(date)
                      can i consider year variable from my dataset as the same like the year in # 6 and #9

                      Q6:Can i use week_start as a week variable just like in #15 .or date in #2 and # 6

                      Below is my time variable format is in belolew examp.


                      Code:
                      * Example generated by -dataex-. To install: ssc install dataex
                      clear
                      input str7 trdwnt int year float(opndt clsdt week_start week_end)
                      "2002-01" 2002 15344 15344 15340 15344
                      "2002-02" 2002 15347 15351 15347 15351
                      "2002-03" 2002 15354 15358 15354 15358
                      "2002-04" 2002 15361 15365 15361 15365
                      "2002-05" 2002 15368 15372 15368 15372
                      "2002-06" 2002 15375 15379 15375 15379
                      "2002-09" 2002 15396 15400 15396 15400
                      "2002-10" 2002 15403 15407 15403 15407
                      "2002-11" 2002 15410 15414 15410 15414
                      "2002-12" 2002 15417 15421 15417 15421
                      "2002-13" 2002 15424 15428 15424 15428
                      "2002-14" 2002 15431 15435 15431 15435
                      "2002-15" 2002 15438 15442 15438 15442
                      "2002-16" 2002 15445 15449 15445 15449
                      "2002-17" 2002 15452 15456 15452 15456
                      "2002-18" 2002 15459 15460 15459 15463
                      "2002-19" 2002 15468 15470 15466 15470
                      "2002-20" 2002 15473 15477 15473 15477
                      "2002-21" 2002 15480 15484 15480 15484
                      "2002-22" 2002 15487 15491 15487 15491
                      "2002-23" 2002 15494 15498 15494 15498
                      "2002-24" 2002 15501 15502 15501 15505
                      "2002-25" 2002 15509 15512 15508 15512
                      "2002-26" 2002 15515 15519 15515 15519
                      "2002-27" 2002 15522 15526 15522 15526
                      "2002-28" 2002 15529 15533 15529 15533
                      "2002-29" 2002 15536 15540 15536 15540
                      "2002-30" 2002 15543 15547 15543 15547
                      "2002-31" 2002 15550 15554 15550 15554
                      "2002-32" 2002 15557 15561 15557 15561
                      "2002-33" 2002 15564 15568 15564 15568
                      "2002-34" 2002 15571 15575 15571 15575
                      "2002-35" 2002 15578 15582 15578 15582
                      "2002-36" 2002 15585 15589 15585 15589
                      "2002-37" 2002 15592 15596 15592 15596
                      "2002-38" 2002 15599 15603 15599 15603
                      "2002-39" 2002 15606 15610 15606 15610
                      "2002-41" 2002 15621 15624 15620 15624
                      "2002-42" 2002 15627 15631 15627 15631
                      "2002-43" 2002 15634 15638 15634 15638
                      "2002-44" 2002 15641 15645 15641 15645
                      "2002-45" 2002 15648 15652 15648 15652
                      "2002-46" 2002 15655 15659 15655 15659
                      "2002-47" 2002 15662 15666 15662 15666
                      "2002-48" 2002 15669 15673 15669 15673
                      "2002-49" 2002 15676 15680 15676 15680
                      "2002-50" 2002 15683 15687 15683 15687
                      "2002-51" 2002 15690 15694 15690 15694
                      "2002-52" 2002 15697 15701 15697 15701
                      "2002-53" 2002 15704 15708 15704 15708
                      "2003-02" 2003 15711 15715 15711 15715
                      "2003-03" 2003 15718 15722 15718 15722
                      "2003-04" 2003 15725 15729 15725 15729
                      "2003-05" 2003 15732 15734 15732 15736
                      "2003-07" 2003 15746 15750 15746 15750
                      "2003-08" 2003 15753 15757 15753 15757
                      "2003-09" 2003 15760 15764 15760 15764
                      "2003-10" 2003 15767 15771 15767 15771
                      "2003-11" 2003 15774 15778 15774 15778
                      "2003-12" 2003 15781 15785 15781 15785
                      "2003-13" 2003 15788 15792 15788 15792
                      "2003-14" 2003 15795 15799 15795 15799
                      "2003-15" 2003 15802 15806 15802 15806
                      "2003-16" 2003 15809 15813 15809 15813
                      "2003-17" 2003 15816 15820 15816 15820
                      "2003-18" 2003 15823 15825 15823 15827
                      "2003-20" 2003 15837 15841 15837 15841
                      "2003-21" 2003 15844 15848 15844 15848
                      "2003-22" 2003 15851 15855 15851 15855
                      "2003-23" 2003 15858 15862 15858 15862
                      "2003-24" 2003 15865 15869 15865 15869
                      "2003-25" 2003 15872 15876 15872 15876
                      "2003-26" 2003 15879 15883 15879 15883
                      "2003-27" 2003 15886 15890 15886 15890
                      "2003-28" 2003 15893 15897 15893 15897
                      "2003-29" 2003 15900 15904 15900 15904
                      "2003-30" 2003 15907 15911 15907 15911
                      "2003-31" 2003 15914 15918 15914 15918
                      "2003-32" 2003 15921 15925 15921 15925
                      "2003-33" 2003 15928 15932 15928 15932
                      "2003-34" 2003 15935 15939 15935 15939
                      "2003-35" 2003 15942 15946 15942 15946
                      "2003-36" 2003 15949 15953 15949 15953
                      "2003-37" 2003 15956 15960 15956 15960
                      "2003-38" 2003 15963 15967 15963 15967
                      "2003-39" 2003 15970 15974 15970 15974
                      "2003-40" 2003 15977 15978 15977 15981
                      "2003-41" 2003 15986 15988 15984 15988
                      "2003-42" 2003 15991 15995 15991 15995
                      "2003-43" 2003 15998 16002 15998 16002
                      "2003-44" 2003 16006 16009 16005 16009
                      "2003-45" 2003 16012 16016 16012 16016
                      "2003-46" 2003 16019 16023 16019 16023
                      "2003-47" 2003 16026 16030 16026 16030
                      "2003-48" 2003 16033 16037 16033 16037
                      "2003-49" 2003 16040 16044 16040 16044
                      "2003-50" 2003 16047 16051 16047 16051
                      "2003-51" 2003 16054 16058 16054 16058
                      "2003-52" 2003 16061 16065 16061 16065
                      "2003-53" 2003 16068 16072 16068 16072
                      end
                      format %td opndt
                      format %td clsdt
                      format %td week_start
                      format %td week_end
                      label var trdwnt "Trading Week '"
                      list trdwnt year opndt clsdt week_start week_end, sepby(week_start)

                      +----------------------------------------------------------------+
                      | trdwnt year opndt clsdt week_st~t week_end |
                      |----------------------------------------------------------------|
                      1. | 2002-01 2002 04jan2002 04jan2002 31dec2001 04jan2002 |
                      |----------------------------------------------------------------|
                      2. | 2002-02 2002 07jan2002 11jan2002 07jan2002 11jan2002 |
                      |----------------------------------------------------------------|
                      3. | 2002-03 2002 14jan2002 18jan2002 14jan2002 18jan2002 |
                      |----------------------------------------------------------------|
                      4. | 2002-04 2002 21jan2002 25jan2002 21jan2002 25jan2002 |
                      |----------------------------------------------------------------|
                      5. | 2002-05 2002 28jan2002 01feb2002 28jan2002 01feb2002 |
                      |----------------------------------------------------------------|
                      6. | 2002-06 2002 04feb2002 08feb2002 04feb2002 08feb2002 |
                      |----------------------------------------------------------------|
                      7. | 2002-09 2002 25feb2002 01mar2002 25feb2002 01mar2002 |
                      |----------------------------------------------------------------|
                      8. | 2002-10 2002 04mar2002 08mar2002 04mar2002 08mar2002 |
                      |----------------------------------------------------------------|
                      9. | 2002-11 2002 11mar2002 15mar2002 11mar2002 15mar2002 |
                      |----------------------------------------------------------------|


                      looking forward to your cooperation.thank you.
                      Ayub





                      Last edited by Ayub UOM; 29 Sep 2019, 08:01.

                      Comment


                      • #41
                        Clyde Schechter
                        Hi.
                        I just need some guidance, about your thread #15 above
                        Code:
                         gen weighted_mean_industry_return= ///     (total_industry_return - weekly_return*weight)/(sum_of_weights - weight)
                        are these two equal ?
                        total_industry_return = weighted_total_industry_return
                        if yes then ok, otherwise can i calculate total_industry_return as
                        by industry_id week , sort: egen total_industry_return = total(weekly_return)
                        Best regards.
                        Last edited by Ayub UOM; 23 Oct 2019, 21:19.

                        Comment


                        • #42
                          i also want to EXCLUDE FIRMS WITH 0 RETURN FOR 7 OR MORE WEEKS, in # 15 above, I think this is based on an overall sample, can I change it to by firm_id year
                          Code:
                           
                            by firm_id, sort: egen weeks_of_zero_return = total(weekly_return == 0)
                          Code:
                           
                           by firm_id year, sort: egen weeks_of_zero_return = total(weekly_return == 0)

                          Comment


                          • #43
                            respected statalist members,
                            I think my questions are very easy or not to the point,thats why not yet answerd,therefore i want to ask it again,sorry for that.But
                            could you please guide me about my questions in above thread #41 and #42 .Although it is already mentioned in #11,so can i replace # 11 in #15 ?
                            best regards.
                            Last edited by Ayub UOM; 25 Oct 2019, 20:35.

                            Comment


                            • #44
                              Q1.what is the difference between these two commands, in the first case (#11) , only 600 observation are dropped from my dataset

                              Code:

                              egen zero_return_weeks = total(weekly_return == 0), by(firm_id year) drop if zero_return_weeks >= 7
                              but when i am using command in # 15 then 787608 observation is dropped from my data set out of total 17 lac,so what is the reason behind this

                              Code:

                              // EXCLUDE FIRMS WITH 0 RETURN FOR 7 OR MORE WEEKS by firm_id, sort: egen weeks_of_zero_return = tota
                              The difference is that the first set of commands drops firms when the number of weeks with zero return is greater than or equal to 7, but the second does so only when it is strictly greater than 7.

                              are these two equal ?

                              total_industry_return = weighted_total_industry_return



                              if yes then ok, otherwise can i calculate total_industry_return as

                              by industry_id week , sort: egen total_industry_return = total(weekly_return)


                              I don't understand what you are asking here. Evidently the weighted total industry return is calculated with weighting, and the total industry return is not--so in general they will be different. But that is obvious, so I imagine I have missed the point of your question.

                              i also want to EXCLUDE FIRMS WITH 0 RETURN FOR 7 OR MORE WEEKS, in # 15 above, I think this is based on an overall sample, can I change it to by firm_id year
                              Code:

                              by firm_id, sort: egen weeks_of_zero_return = total(weekly_return == 0)
                              Code:

                              by firm_id year, sort: egen weeks_of_zero_return = total(weekly_return == 0)
                              Yes, this is a correct conversion from total weeks of zero return for the firm over its entire lifetime to total weeks of zero return for the firm in each year.

                              Comment


                              • #45
                                Clyde Schechter
                                Thank you professor for your time,i got the answer and noted the exact point now.
                                my another question was,
                                How can i generate
                                total_industry_return
                                in the below equtaion ? so that i can put its value in the final eqution.
                                Code:
                                    
                                 CALCULATE WEIGHTED MEAN EXCLUDING INDEX FIRM by industry_id week, sort:  egen weighted_total_industry_return = total(weekly_return*weight) by industry_id week: egen sum_of_weights = total(weight) // BY DIVIDING WEIGHTED TOTAL BY SUM OF WEIGHTS // AFTER SUBTRACTING OUT THE FIRM'S CURRENT WEEKLY RETURN AND WEIGHT gen weighted_mean_industry_return= ///     (total_industry_return - weekly_return*weight)/(sum_of_weights - weight)  //
                                i hope my question will be clear.

                                Comment

                                Working...
                                X