Announcement

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

  • Ascol command: r(3301) error

    Dear all,

    After trying multiple ways to work around an error issued by Stata after running the ascol command, I decided to turn to you, the community, in hope of a work around. To try and explain the issue as clear as possible, the following context:

    For the past month I have been working on my thesis regarding momentum strategies within Stata with a dataset containing daily returns data. As my holding periods and lookback periods are monthly, I decided to use the ascol command to convert daily returns data to monthly returns data. This has worked perfectly on consecutive days, but Stata suddenly issued an error - r(3301) - for the ascol command last week. My dataset has not changed between the days that the command worked and the day it did not anymore. Moreover, by cross-referencing my do.files of days previous to the error and the day of the error, it shows that my code has stayed exactly the same. Lastly, Stata also issues the r(3301) error when the example syntax given under help ascol by professor Shah is ran . See below;

    Code:
    clear
    set obs 1000
    number of observations (_N) was 0, now 1,000
    
    gen date=date("1/1/2012" , "DMY")+_n
    
    format %td date
    
    tsset date
    time variable: date, 02jan2012 to 27sep2014
    delta: 1 day
    
    gen pr=10
    
    replace pr=pr[_n-1]+uniform() if _n>1
    (999 real changes made)
    
    gen simpleRi=(pr/l.pr)-1
    (1 missing value generated)
    
    gen logRi = ln(pr/l.pr)
    (1 missing value generated)
    
    save stocks,replace
    (note: file stocks.dta not found)
    file stocks.dta saved
    
    use stocks, clear
    
    ascol simpleRi, toweek returns(simple)
    PRODUCT(): 3301 subscript invalid
    asrolnw(): - function returned error
    <istmt>: - function returned error
    r(3301);
    Hence the following approach: I ran count to count the values in the Returns variable that are either larger/smaller/equal than 0 or missing. The addition of these counts is equal to the total amount of observations, namely 807,798. There are no non-numeric values within this variable. This was done in light of the following forum post: https://www.statalist.org/forums/for...-daily-returns

    The return values use dots as decimal points. I have xtset my data with the time variable being Date and the panel variable being instrument. The delta is equal to 1 day. The Returns- and instrument data is in long form.

    The following syntax is used, and gives:

    Code:
    order Date instrument Returns
    sort Instrument Date
    ssc install ascol, replace
    xtset instrument Date
     panel variable:  instrument (strongly balanced)
            time variable:  Date, 1/1/1997 to 12/31/2020, but with gaps
                    delta:  1 day
    ascol Returns, tomonth returns(simple)
    PRODUCT(): 3301 subscript invalid
    asrolnw(): - function returned error
    <istmt>: - function returned error
    Below I provided an example of the dataset that I'm using. Interestingly, the ascol command does generate the month_id variable, which denotes a month-year value.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int Date long instrument double Returns float month_id
    13515 1                      0 444
    13516 1   -.008319581858813763 444
    13517 1     .00457925396040082 444
    13520 1   .0005707734380848706 444
    13521 1 -.00031615333864465356 444
    13522 1   -.003439552616328001 444
    13523 1   .0011100437259301543 444
    13524 1   -.006406460888683796 444
    13527 1     .00453687971457839 444
    13528 1    .007646918762475252 444
    13529 1   .0003425455652177334 444
    13530 1   .0011692713014781475 444
    13531 1   .0011079214746132493 444
    13534 1  -.0033540083095431328 444
    13535 1   .0016926343087106943 444
    13536 1   .0021689054556190968 444
    13537 1   -.004844727460294962 444
    13538 1   -.006304330192506313 444
    13541 1   -.006935999728739262 444
    13542 1   .0008831917657516897 444
    13543 1   .0034703402779996395 444
    13544 1    .004929186310619116 444
    13545 1    .007448762655258179 444
    13548 1   .0015082336030900478 445
    13549 1    .002111880574375391 445
    13550 1   -.005057091824710369 445
    13551 1  -.0004970584413968027 445
    13552 1    .004229959566146135 445
    13555 1    .002606478286907077 445
    13556 1  .00035289672086946666 445
    13557 1   .0044128065928816795 445
    13558 1    .006446360144764185 445
    13559 1   .0014054387575015426 445
    13562 1  -.0008126712637022138 445
    13563 1   .0017570068594068289 445
    13564 1   -.001928934594616294 445
    13565 1  -.0027721247170120478 445
    13566 1   .0006425472674891353 445
    13569 1   .0035680062137544155 445
    13570 1    .002302951645106077 445
    13571 1   -.009938579052686691 445
    13572 1  -.0033261356875300407 445
    13573 1   -.004065744578838348 445
    13576 1   -.000890459748916328 446
    13577 1  -.0012739701196551323 446
    13578 1    .003478868631646037 446
    13579 1  -.0020837606862187386 446
    13580 1    .004422342870384455 446
    13583 1    .005043782759457827 446
    13584 1 .000018912960513262078 446
    13585 1   -.006473993416875601 446
    13586 1   -.011649202555418015 446
    13587 1    .002654843498021364 446
    13590 1   -.002201056107878685 446
    13591 1   -.001345948432572186 446
    13592 1  -.0015786869917064905 446
    13593 1   -.005527653731405735 446
    13594 1   .0037200013175606728 446
    13597 1   .0009054978145286441 446
    13598 1    .001265001017600298 446
    13599 1    .001498362049460411 446
    13600 1   -.008201058022677898 446
    13601 1 -.00046907292562536895 446
    13604 1   -.006773156579583883 446
    13605 1  -.0036032437346875668 447
    13606 1   -.002837984822690487 447
    13607 1   -.001309104380197823 447
    13608 1  -.0006392689538188279 447
    13611 1    .001706025330349803 447
    13612 1   .0012044014874845743 447
    13613 1  -.0028257789090275764 447
    13614 1  -.0023580079432576895 447
    13615 1   -.010415947064757347 447
    13618 1 -.00040106510277837515 447
    13619 1    .010240552946925163 447
    13620 1   .0048467605374753475 447
    13621 1     .00260004960000515 447
    13622 1   .0036989341024309397 447
    13625 1  -.0001993210316868499 447
    13626 1    .005547693464905024 447
    13627 1   .0005947300232946873 447
    13628 1  -.0020678217988461256 447
    13629 1   -.005629931576550007 447
    13632 1   .0029355769511312246 447
    13633 1    .014730594120919704 447
    13634 1    .006960650905966759 447
    13635 1    .002009183634072542 448
    13636 1    .006769500207155943 448
    13639 1   .0073029897175729275 448
    13640 1   .0061397491954267025 448
    13641 1   -.006584391929209232 448
    13642 1    .003818472847342491 448
    13643 1   .0054987212643027306 448
    13646 1    .009617207571864128 448
    13647 1  -.0021256529726088047 448
    13648 1    .003446330549195409 448
    13649 1    .002576211467385292 448
    13650 1   -.002311837626621127 448
    13653 1  -.0007871178677305579 448
    13654 1      .0040381602011621 448
    end
    format %tdnn/dd/CCYY Date
    format %tm month_id
    label values instrument Indices
    label def Indices 1 "60_40", modify
    Any help/tip/insight is dearly appreciated!
    Last edited by Bram Theeven; 22 Jul 2021, 06:29.
Working...
X