Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: Collapse - How does it collapse


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Collapse - How does it collapse
Date   Sat, 25 Jun 2011 20:13:29 +0100

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 <dawood_ashraf@yahoo.com> 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?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index