Statalist


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

st: RE: how to change specific string variable into date variable?


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: how to change specific string variable into date variable?
Date   Tue, 11 Aug 2009 21:26:56 +0200

<>

Probably safer to first convert the string to a -date- and then start any
translation/extraction action...

***
clear
input country:mylabel /* 
 */ str10 date, auto 
Argentina   "199001"
Argentina   "199001"
Argentina   "199001"
Argentina   "199002"
Argentina   "199003"
Argentina   "199004"
Argentina   "199004"
Argentina   "199004"
Argentina   "199004"
Argentina   "199101"
Argentina   "199101"
Argentina   "200803"
Argentina   "200804"
Argentina   "200804"
Brazil      "199001"
Brazil      "199002"
Brazil      "199002"
Brazil      "199003"
Brazil      "199003"
Brazil      "199003"
Brazil      "199003"
end
compress

gen double date2=/*
*/date(date,"YM")

gen double month=/*
*/month(date2)

list, noobs /*
*/ sepby(cou)

***


HTH
Martin

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of gjhxmu@sina.com
Sent: Dienstag, 11. August 2009 19:46
To: statalist
Subject: st: how to change specific string variable into date variable?

Dear statalists,

Something wrong happened when changing the string variable into date
variable.

 clear
input country:mylabel /* 
 */ str10 date, auto 
Argentina   "199001"
Argentina   "199001"
Argentina   "199001"
Argentina   "199002"
Argentina   "199003"
Argentina   "199004"
Argentina   "199004"
Argentina   "199004"
Argentina   "199004"
Argentina   "199101"
Argentina   "199101"
Argentina   "200803"
Argentina   "200804"
Argentina   "200804"
Brazil      "199001"
Brazil      "199002"
Brazil      "199002"
Brazil      "199003"
Brazil      "199003"
Brazil      "199003"
Brazil      "199003"
end
g date2=monthly(date,"YM")

The result showed "21 missing values generated"

Anything wrong? How to correct it ?

Thank you for any help!

Best regards,
Rose.


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


*
*   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   |   What's new   |   Site index