Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: date function


From   Arun Rajamohan <[email protected]>
To   [email protected]
Subject   Re: st: date function
Date   Wed, 06 Feb 2008 15:59:56 -0500

Hope this helps...
     +-----+
     | mon |
     |-----|
  1. | jan |
  2. | feb |
  3. | mar |
  4. | apr |
  5. | may |
     |-----|
  6. | jun |
     +-----+

. gen dat=date(mon, "M")

. l

     +-----------+
     | mon   dat |
     |-----------|
  1. | jan     0 |
  2. | feb    31 |
  3. | mar    60 |
  4. | apr    91 |
  5. | may   121 |
     |-----------|
  6. | jun   152 |
     +-----------+

. format dat %td

. l

     +-----------------+
     | mon         dat |
     |-----------------|
  1. | jan   01jan1960 |
  2. | feb   01feb1960 |
  3. | mar   01mar1960 |
  4. | apr   01apr1960 |
  5. | may   01may1960 |
     |-----------------|
  6. | jun   01jun1960 |
     +-----------------+

. gen mon2=month(dat)

. l

     +------------------------+
     | mon         dat   mon2 |
     |------------------------|
  1. | jan   01jan1960      1 |
  2. | feb   01feb1960      2 |
  3. | mar   01mar1960      3 |
  4. | apr   01apr1960      4 |
  5. | may   01may1960      5 |
     |------------------------|
  6. | jun   01jun1960      6 |
     +------------------------+

-Arun

On Feb 6, 2008, at 3:42 PM, Visintainer, Paul wrote:

Is there a date function that converts a string variable containing only the text of the month into a numeric version of the month?  e.g.:  X has string values October, April, December, etc.  I want to create a new variable that is numeric with numbers 10, 04, 12, etc.   I thought -monthly( )- would do it, but I can't seem to get the right syntax.

Thanks.

-p


______________________________________
Paul F. Visintainer, PhD

*
*   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/

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Arun Rajamohan PhD
Department of Biology
Room 237, Biological & Geological Sciences Building
1151 Richmond Street North
The University of Western Ontario
London, ON N6A 5B7 CANADA
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~





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