Statalist


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

RE: st: date function


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: date function
Date   Wed, 6 Feb 2008 22:28:19 -0000

This can be telescoped, e.g. 

. di month(date("october", "M"))
10

Thus 

. gen byte month = month(date(X, "M")) 

Nick 
[email protected] 

Arun Rajamohan

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 |
�� � +------------------------+

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.


*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index