Announcement

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

  • Compute sum of a variable with a specified dates

    Dear Stata Users,

    I have a data specified below. I need to calcualte a sum of "profit" specified by "main_date" for each row between the "sales_date" and "Purchase_date". Say, if "Sales_date" is Dec 10, 2000 and "Purchase_date" is Jan 1, 2005, I need the sum of "profit" over "main_date" that is from " Dec 10, 2000 to Jan 1, 2005. Please, help me with this issue.


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double cusip long main_date int Sales_date float profit long Purchase_date
    17478 19460 18345    .01196245 671681
    17478 19463 18352   .000918216 671681
    17478 19464 18352    .01048236 671681
    17478 19465 18374  .0003315355 671681
    17478 19466 18374 -.0016606566 671681
    17478 19467 18374   -.00176864 671681
    17478 19470 18380  -.011765366 671681
    17478 19471 18381 -.0023171413 671681
    17478 19472 18382  -.009053134 671681
    17478 19473 18387   .010571496 671681
    17478 19474 18387   .020698626 671681
    17478 19477 18394   .009863095 671681
    17478 19478 18395   .007459788 671681
    17478 19479 18395  -.012370364 671681
    17478 19480 18396 .00023604836 671681
    17478 19481 18402  -.004663667 671681
    17478 19484 18424  .0008493518 671681
    17478 19485 18429   .002819395 671681
    17478 19486 18431 -.0008591413 671681
    17478 19487 18438    .01303303 671681
    17478 19488 18442  -.009200668 671681
    17478 19491 18443  -.002530745 671681
    17478 19492 18459  .0006412752 671681
    17478 19493 18465 -.0025009736 671681
    17478 19494 18480  -.006696461 671681
    17478 19495 18480  -.012039206 671681
    17478 19498 18485   .008824927 671681
    17478 19499 18486  -.007382274 671681
    17478 19500 18508  -.009324818 671681
    end
    format %tdDD/NN/CCYY main_date
    format %tdDD/NN/CCYY Sales_date
    format %tdDD/NN/CCYY Purchase_date

  • #2
    Your question is not clear to me. Could you please
    • check your demonstration dataset, and label the variables. E.g. , is there only one purchase date per cusid? what is cusid? etc.
    • show an example of your desired dataset.
    However, I am guessing that you can solve the problem using rangestat or rangerun.

    Code:
    ssc install rangestat
    help rangestat
    
    ssc install rangerun
    help rangerun

    Comment

    Working...
    X