Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Extracting column information


From   wgould@stata.com (William Gould, Stata)
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Extracting column information
Date   Wed, 05 Nov 2003 08:20:25 -0600

Michael Carney <carneymh@bc.edu> writes, 

> I have a data set of security prices over time, each price corresponding to
> a date column in the format, e.g., 8-Aug-1998. If I would like to take the
> prices for the first ten days of the month and place these prices in a
> separate column what commands should I use?

The Stata function date(<date>,<format>) converts a string date to an 
integer recording the number of days 1jan1960, for example:

        . display date("8-Aug-1998","dmy")
        14099

The second argument, "dmy", indicates that the string is in the format 
day followed month followed by year.

The Stata function day(<statadate>) returns the day of the month.  For 
instance, 

        . display day(14099)
        8

Therefore, one solution to the problem is:

        . gen newprice = price if day(date(origdate,"dmy"))<=10

-- Bill
wgould@stata.com
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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   |   What's new   |   Site index