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

Re: st: Extracting column information

From (William Gould, Stata)
Subject   Re: st: Extracting column information
Date   Wed, 05 Nov 2003 08:20:25 -0600

Michael Carney <> 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")

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 

        . display day(14099)

Therefore, one solution to the problem is:

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

-- Bill
*   For searches and help try:

© Copyright 1996–2023 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index