Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Collapse - How does it collapse


From   Dawood Ashraf <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Collapse - How does it collapse
Date   Sat, 25 Jun 2011 21:33:21 -0700 (PDT)

Thanks Nick. 

It worked out very well. Just as a reference if someone else may need this in future. I am appending below how I did this.


. generate newdate= mofd(valdate)
. format  newdate %tm
. describe newdate
              storage  display     value
variable name   type   format      label      variable label
---------------------------------------------------------------------------------------------------------------------------------------------
newdate         float  %tm                    
. su  price
    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
       price |    116251    130.5486    818.1193      .0712     184587

. collapse (mean) nav price sharia, by (newdate id)

. su  price
    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
       price |     12322    116.7652    628.9435    .266525    36931.8
. 


Dawood

----- Original Message -----
From: Nick Cox <[email protected]>
To: [email protected]
Cc: 
Sent: Saturday, June 25, 2011 10:13:29 PM
Subject: Re: st: Collapse - How does it collapse

You are confusing format with value. Setting the display format of a
daily date does not affect its value: it just affects how and what is
displayed.

You need a conversion function, notably -mofd()-. Consider

. di mofd(date("25 June 2011", "DMY"))
617

. di %tm  mofd(date("25 June 2011", "DMY"))
2011m6

This may not seem different, but it really is. The underlying date is
600-odd months from January 1960, namely 50 years plus some.

Create a monthly variable that way from your daily dates, and then you
can use that in the -collapse-.

Nick

On Sat, Jun 25, 2011 at 10:14 AM, Dawood Ashraf <[email protected]> wrote:

> I have historical daily price data of mutual funds and I am trying to 'collapse' it in monthly. I followed the collapse command as suggested in the manual and I believe this shoudl work. However, the number of observations does not change that I believe should after collapse from daily to monthly data.
>
> .  generate newdate = date(vdate, "MDY")          /this converts the string valuation date to non-string)?
> . format newdate %tm                                     /This converts date from %td to %tm - the possible error could be here?
> . describe
> Contains data from D:\Mutual Fund Data\MutualFundData_clean.dta
>   obs:       116,251
>  vars:            10                          25 Jun 2011 00:32
>  size:    55,800,480 (89.4% of memory free)
> ---------------------------------------------------------------------------------------------------------------------------------------------
>               storage  display     value
> variable name   type   format      label      variable label
> ---------------------------------------------------------------------------------------------------------------------------------------------
> name            str143 %143s                  Fund Name
> manager         str200 %200s                  Fund Manager
> type            str100 %100s                  Type of Fund
> nav             double %8.0g                  Net Asset Value
> price           float  %8.0g                  Unit Price
> vdate           str10  %10s                   Valuation Date
> id              int    %8.0g                  Identifier
> valdate         float  %9.0g
> sharia          byte   %8.0g                  type==Shari'ah Compliant
> newdate         float  %tm
> ---------------------------------------------------------------------------------------------------------------------------------------------
> Sorted by:  id  valdate
>      Note:  dataset has changed since last saved
>
> . collapse (mean) nav price sharia, by (newdate id)
>
> . su price
>     Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>        price |    116251    130.5486    818.1193      .0712     184587
>
> If you see here number of observations are still 116251. The number should reduce since the data is monthly now.

*
*  For searches and help try:
*  http://www.stata.com/help.cgi?searchhttp://www.stata.com/support/statalist/faqhttp://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index