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

RE: handling date data (was st: Please help!)

From   "umit ozmel" <>
To   <>
Subject   RE: handling date data (was st: Please help!)
Date   Tue, 18 May 2004 18:20:27 -0400


I am trying to take the first two characters of a string variable using
substr command as below:

name2 = substr(name,1,2)

However I get an error message of " type mismatch". Any idea about how I can
handle this?

-----Original Message-----
[]On Behalf Of Lisa Sharwood
Sent: Monday, May 17, 2004 1:57 AM
Subject: Re: handling date data (was st: Please help!)

>Hello Lisa
>Welcome to Stata.
>(Just an initial tip: a meaningful Subject: header is likely to lead
>to a faster response from the list than a generic "Please help!".)
>You have, I surmise, 2 variables, call them timeA and timeB, which
>represent each observation's date of entry to the study and exit
>from the study respectively.  Given the dates are in Stata's elapsed
>     generate studytime = timeB - timeA
>gives you a new variable, studytime, that represents the
>time-on-study for _every_ observation (ie each subject).  Stata does
>not need to explicitly loop through observations to do this type of
>thing - it does the operation on every observation unless you
>instruct otherwise.  You instruct otherwise using the -if- or -in-
>command qualifiers (vide infra).  studytime will, by default, be a
>floating point variable and you may wish, since time in days is
>integer, choose another data type, for example:
>     generate long studytime = timeB - timeA
>to give studytime a "long integer" type.  see help datatypes; maybe
>type "int" will be sufficient for your needs?
>You can then use Stata's -list-  -summarize-  and other commands to
>look at the studytime.
>[Actually, you now have a time-on-study variable, studytime, so you
>could jump straight into the world of survival analysis. All you
>need to -stset- your data, the passport into that world, is such a
>time variable.  See -help st- and thence -help stset-.]
>If you wished to generate the studytime for only subjects 108
>through 215 then you could:
>   generate long studytime = timeB - timeA in 108/215
>but this is very dependent on the current sort order of the data so
>be sure that these really are the subjects on whom you wish to
>calculate the new variable.  All other observations will be accorded
>a missing value on studytime.
>It is probably safer to give these subjects a flag or indicator
>based on the substantive reason why they are important as a subgroup
>and use that indicator to select on subsequent manipulations and
>I hope this helps.  New users of Stata often benefit greatly by
>taking one of the Stata "Netcourses".  I note from
>  that an introductory course
>begins in June.  Might be worth a look.
>At 04:38 PM 11/05/2004 +1000, you wrote:
>>Hello and thank you for attending to my enquiry!!
>>I am a very new Stata user and plowing through the user guide and
>>reference manuals to try and perform a calculation.... and I need
>>help please!
>>I have two variables for which I have converted the list of dates
>>into real elapsed dates. I want to subtract one from the other and
>>thus generate a new variable with that figure.. which will give me
>>the amount of time the person has stayed in the study. I have
>>managed to
>>'compare' the two variables but only in one observation at a time.
>>Could you please tell me how to do it for all the observations, and
>>can I use 'in 108/215'  for example.
>>I hope this is understandable and I hope to hear from you soon. My
>>ultimate aim is to perform Kaplan Mieir survival analysis on the
>>Thank you
>>Lisa Sharwood
>>Research Officer
>>Neurosciences Institute, Austin Health
>>Melbourne University
>>*   For searches and help try:
>Philip Ryan
>Associate Professor,
>Department of Public Health
>Associate Dean (Information Technology)
>Faculty of Health Sciences
>University of Adelaide 5005
>South Australia
>tel 61 8 8303 3570
>fax 61 8 8223 4075
>CRICOS Provider Number 00123M
>This email message is intended only for the addressee(s)
>and contains information that may be confidential and/or
>copyright. If you are not the intended recipient please
>notify the sender by reply email and immediately delete
>this email. Use, disclosure or reproduction of this email
>by anyone other than the intended recipient(s) is strictly
>prohibited. No representation is made that this email or
>any attachments are free of viruses. Virus scanning is
>recommended and is the responsibility of the recipient.
>*   For searches and help try:

*   For searches and help try:

*   For searches and help try:

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