Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

AW: st: bottom to top or reverse cumulative distribution in table command?


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   AW: st: bottom to top or reverse cumulative distribution in table command?
Date   Thu, 15 Apr 2010 14:08:38 +0200

<> 

Amy, I made up the data via -input-, so other listers can follow my ideas,
but you have your very own data on your end, so ignore everything between
-input- and -end-. -end- lets you exit from -input-, if that is an issue.



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Penn, Amy
Gesendet: Donnerstag, 15. April 2010 14:05
An: [email protected]
Betreff: RE: st: bottom to top or reverse cumulative distribution in table
command?

Dear Stefan and Martin,

Thanks for your fast reply.  I had some further questions regarding both of
your suggestions.  But first, here is an example of how my data looks:

Var1date: Date patient departed from the clinic, example: 12 Nov 09
Var1time: Time patient departed from the clinic, example: 23:47

Var2date: Date patient arrived at the hospital, example: 13 Nov 09
Var2time: Time patient arrived at the hospital, example: 02:32

Stefan: In this example dataset, actual time difference is 2:32 + 13 min =
2:45, or 165 min.   if I subtracted the dates, I would get a 1 day
difference, and you suggested I multiple the 1 day difference by 24*60,
which would already be over 165 min.  Is there a way to calculate 

Martin: I got confused with the coding you offered, partly because I am
stuck here after this (referenced below):
clear /*
inp byte patid Var1date Var2date  /*
      patid Var1date Var2date
1. 

So, after entering those first two lines, I entered "str10(Var1time
Var2time)" and I receive "'str10' cannot be read as a number".  Also I am
trying to exit the program and it won't allow me.  Below I've pasted your
suggested code.

inp byte patid Var1date Var2date  /* 
*/ str10(Var1time Var2time)
1 16874 16871 "12-31" "13-43"
2 16885 16879 "01-11" "10-21"
3 16732 16730   "10-00" "10-00"
end

gen stringVar1=string(Var1date,"%dD_m_Y")+" "+ Var1time
gen stringVar2=string(Var2date,"%dD_m_Y")+" "+ Var2time
gen double minutediff= /* 
*/ minutes(clock(stringVar1, "DM20Yhm")- /* 
*/ clock(stringVar2, "DM20Yhm"))
list, noo

Any help would be greatly appreciated.  Thank you again,
Amy
________________________________________

From: [email protected]
[[email protected]] On Behalf Of Martin Weiss
[[email protected]]
Sent: Thursday, April 15, 2010 4:31 AM
To: [email protected]
Subject: AW: st: bottom to top or reverse cumulative distribution in table
command?

<>

Stefan, how come your subject line suddenly changes to "st: bottom to top or
reverse cumulative distribution in table command?" even though you are
replying to Amy`s "Merging 2 variables to calculate time elapse
(time/date)"? Is this a malfunction of the server?

BTW, - replace Var1time_n = real(Var1time)- implies that "Var1time_n" has
come into being somehow, maybe -generate-d somewhere "upstream". The
-real()- function will accept only strings that can be readily converted to
numeric vars, w/o any removal of dashes, colons etc. So we do need to know
what Amy`s data look like to give further advice...


***
di real("12-31")
di real("1231")
di real("12-31")
***



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von
[email protected]
Gesendet: Donnerstag, 15. April 2010 12:26
An: [email protected]
Betreff: AW: st: bottom to top or reverse cumulative distribution in table
command?

Dear Amy,

Stata date and time functions are somehow confusing at the start but very
nice to work with later.


If you have the dates in Stata format (number of days from 1,1, 1960)
you don't have to care about the formats and just can calculate:
Var2date - Var1date = date difference.
You can multiply the date difference by 24*60 to change it into minutes.


********* Now to the time of day
I can't guess what your time vars contain.

You have a string format (str5) so you need to transfer the string vars into
numeric vars first.
Example:
Replace Var1time_n = real(Var1time)

I suppose the vars contain elapsed seconds or minutes from midnight.
In this case things are rather easy:

You calculate the difference Var2time - Var1time which might be positive or
negative.
Then convert this result into minutes if Var[1/2]time counts other time
measures.

Finally add the time difference to the date difference (both in minutes) and
you have the total difference.

This is one easy way, there are other functions available in the date and
time section but one has to know the exact data specification to use them.

Stefan Gawrich






Dear Statalist users,

I am very much a beginner in Stata, and I have Stata 11.0.  I have read the
?help dates? instructional from Stata, but am still confused.  For my
project in the Zambian hospital setting, I must calculate the elapsed time
in minutes of 2 sets of variables, they are:

Var1date: Date patient departed from the clinic
Var1time: Time patient departed from the clinic

Var2date: Date patient arrived at the hospital
Var2time: Time patient arrived at the hospital

The time variables have type ?str5? and format ?%5s.?  The date variables
have the type ?long? and format ?%dD_m_Y.?  (I also do not quite understand
the meaning of ?str5,? ?%5s,? and ?long.?)

I would like to calculate the time difference (in minutes) between the time
the patient left the clinic to when the patient arrived at the hospital.
How would I merge, for example, Var2date and Var2time into ?Var2? from which
I may subtract Var1 (Var2-Var1 = time transport takes).

Thanks very much for your consideration,
Amy










































Dear Statalist users,

I am very much a beginner in Stata, and I have Stata 11.0.  I have read the
?help dates? instructional from Stata, but am still confused.  For my
project in the Zambian hospital setting, I must calculate the elapsed time
in minutes of 2 sets of variables, they are:

Var1date: Date patient departed from the clinic
Var1time: Time patient departed from the clinic

Var2date: Date patient arrived at the hospital
Var2time: Time patient arrived at the hospital

The time variables have type ?str5? and format ?%5s.?  The date variables
have the type ?long? and format ?%dD_m_Y.?  (I also do not quite understand
the meaning of ?str5,? ?%5s,? and ?long.?)

I would like to calculate the time difference (in minutes) between the time
the patient left the clinic to when the patient arrived at the hospital.
How would I merge, for example, Var2date and Var2time into ?Var2? from which
I may subtract Var1 (Var2-Var1 = time transport takes).

Thanks very much for your consideration,
Amy

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

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index