Thanks, on behalf of those who wanted it.
In terms of your original question I can see two situations here. 1. The data come as ranks. No comment to add. 2. The data do not come as ranks, but working with ranks is a reaction to some queasiness about the data, e.g. outliers, skewness, some other kind of messiness. Even in this situation I would tend to play a bit and consider transformation vs no transformation, or -glm- with different link functions. If the substantive conclusion is that the scale is secondary, you can avoid Kruskal-Wallis. If that the scale is crucial, you (or your client) may need better data. Nick [hidden email] Ricardo Ovaldia Here it is: Sokal, R. R. and F. J. Rohlf. 1995. Biometry: the principles and practice of statistics in biological research. 3rd edition. W. H. Freeman and Co.: New York. > > > From: Nick Cox <[hidden email]> > > Date: Monday, March 15, 2010, 11:22 AM > > . findit Kruskal > > > > turns up what there is. -findit- is a variant on > -search-, > > recommended > > to you in the last thread you started. > > > > Minimal name (year) references are deprecated on this > list. > > But the > > procedure recommended in that book is almost > certainly > > highly > > programmable. > > Ricardo Ovaldia > > > Is there a Post-Hoc test for Kruskal Wallis in Stata? > > Something like the one proposed by Sokal and Rohlf > (1995). * * 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/ |
In reply to this post by Nick Cox
In Stata 10, assuming a qreg regression with one predictor, is there a
way to develop confidence intervals around the qreg trend line (or any quantile for that matter)? Also, once developed, what would be the syntax to then graph the scatter plot, trend line and confidence intervals? Thank you in advance. Jeffrey B. Wolpin * * 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/ |
sysuse auto, clear
gen gpm = 1/mpg qreg gpm weight predict pred predict se, stdp local level = (100 - 95) / 200 gen ul = pred + invttail(e(df_r), `level') * se gen ll = pred - invttail(e(df_r), `level') * se twoway rarea ll ul weight, sort astyle(ci) || /// line pred weight, sort || /// scatter gpm weight, legend(off) ytitle(Gallons per mile) Nick [hidden email] Jeffrey B. Wolpin In Stata 10, assuming a qreg regression with one predictor, is there a way to develop confidence intervals around the qreg trend line (or any quantile for that matter)? Also, once developed, what would be the syntax to then graph the scatter plot, trend line and confidence intervals? * * 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/ |
In reply to this post by Jeff-2
<> Jeffrey may also like the recently updated ************* ssc d grqreg ************* HTH Martin -----Original Message----- From: [hidden email] [mailto:[hidden email]] On Behalf Of Jeff Sent: Montag, 15. März 2010 21:29 To: [hidden email] Subject: RE: st: CIs around Qreg trend line In Stata 10, assuming a qreg regression with one predictor, is there a way to develop confidence intervals around the qreg trend line (or any quantile for that matter)? Also, once developed, what would be the syntax to then graph the scatter plot, trend line and confidence intervals? Thank you in advance. Jeffrey B. Wolpin * * 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/ |
In reply to this post by Nick Cox
Dear Mr. Cox,
Thank you. The example syntax worked great. Question: What is being computed by the line "local level = (100 - 95) / 200"? Is this line in any way dependent upon the number of observations? Alternatively, what does 200 signify. Thanks again and pardon my ignorance. Jeffrey B. Wolpin -----Original Message----- From: [hidden email] [mailto:[hidden email]] On Behalf Of Nick Cox Sent: Monday, March 15, 2010 1:41 PM To: [hidden email] Subject: RE: st: CIs around Qreg trend line sysuse auto, clear gen gpm = 1/mpg qreg gpm weight predict pred predict se, stdp local level = (100 - 95) / 200 gen ul = pred + invttail(e(df_r), `level') * se gen ll = pred - invttail(e(df_r), `level') * se twoway rarea ll ul weight, sort astyle(ci) || /// line pred weight, sort || /// scatter gpm weight, legend(off) ytitle(Gallons per mile) Nick [hidden email] Jeffrey B. Wolpin In Stata 10, assuming a qreg regression with one predictor, is there a way to develop confidence intervals around the qreg trend line (or any quantile for that matter)? Also, once developed, what would be the syntax to then graph the scatter plot, trend line and confidence intervals? * * 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/ |
<> " What is being computed by the line "local level = (100 - 95) / 200"?" Try Maarten`s http://www.stata-journal.com/article.html?article=st0137 to get a handle on this issue. Preprint at http://www.uni-tuebingen.de/fileadmin/Uni_Tuebingen/Fakultaeten/SozialVerhal ten/Institut_fuer_Soziologie/Dokumente/Pdf_Dateien/Buis/p-value_pdf.pdf HTH Martin -----Original Message----- From: [hidden email] [mailto:[hidden email]] On Behalf Of Jeff Sent: Dienstag, 16. März 2010 00:27 To: [hidden email] Subject: RE: st: CIs around Qreg trend line Dear Mr. Cox, Thank you. The example syntax worked great. Question: What is being computed by the line "local level = (100 - 95) / 200"? Is this line in any way dependent upon the number of observations? Alternatively, what does 200 signify. Thanks again and pardon my ignorance. Jeffrey B. Wolpin -----Original Message----- From: [hidden email] [mailto:[hidden email]] On Behalf Of Nick Cox Sent: Monday, March 15, 2010 1:41 PM To: [hidden email] Subject: RE: st: CIs around Qreg trend line sysuse auto, clear gen gpm = 1/mpg qreg gpm weight predict pred predict se, stdp local level = (100 - 95) / 200 gen ul = pred + invttail(e(df_r), `level') * se gen ll = pred - invttail(e(df_r), `level') * se twoway rarea ll ul weight, sort astyle(ci) || /// line pred weight, sort || /// scatter gpm weight, legend(off) ytitle(Gallons per mile) Nick [hidden email] Jeffrey B. Wolpin In Stata 10, assuming a qreg regression with one predictor, is there a way to develop confidence intervals around the qreg trend line (or any quantile for that matter)? Also, once developed, what would be the syntax to then graph the scatter plot, trend line and confidence intervals? * * 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/ |
In reply to this post by Ricardo Ovaldia
Ricardo Ovaldia wrote:
Is there a Post-Hoc test for Kruskal Wallis in Stata? Something like the one proposed by Sokal and Rohlf (1995). -------------------------------------------------------------------------------- I'm not sure whether it's the same test that you're referring to, but last summer I had an occasion to program the Dwass, Steel, Critchlow-Fligner test. I used M. Hollander & D. A. Wolfe, _Nonparametric Statistical Methods_ Second Edition. (New York: John Wiley & Sons, 1999) pp. 240--44 as the source for the formula and for the worked example to verify the ado file's output. It's not difficult to program, but I'll put it up on SSC once I write a help file. You'll need to install John Gleason's -qsturng- from SSC in order to get the reference distribution for the test statistic (Studentized range) if you want to avoid manual look-up. Joseph Coveney * * 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/ |
In reply to this post by Jeff-2
(100 - 95) / 200 is .025 as I presume you know or can work out for
yourself. The result is put in a local macro called -level- which is then fed as one argument to the -invttail()- function. In this case, you get a 95% confidence interval. The other argument is the number of residual degrees of freedom to play with. The element "df" is a clue here. To get this example, I modified some code that you can see for a similar problem in . ssc type rcspline.ado I use this form because it is then easy to see that for "different values of 95", you would just plug in something else instead of 95, e.g. local level = (100 - 90) / 200 is the different line needed for a 90% confidence interval. Nick [hidden email] Jeffrey B. Wolpin Thank you. The example syntax worked great. Question: What is being computed by the line "local level = (100 - 95) / 200"? Is this line in any way dependent upon the number of observations? Alternatively, what does 200 signify. Nick Cox sysuse auto, clear gen gpm = 1/mpg qreg gpm weight predict pred predict se, stdp local level = (100 - 95) / 200 gen ul = pred + invttail(e(df_r), `level') * se gen ll = pred - invttail(e(df_r), `level') * se twoway rarea ll ul weight, sort astyle(ci) || /// line pred weight, sort || /// scatter gpm weight, legend(off) ytitle(Gallons per mile) Jeffrey B. Wolpin In Stata 10, assuming a qreg regression with one predictor, is there a way to develop confidence intervals around the qreg trend line (or any quantile for that matter)? Also, once developed, what would be the syntax to then graph the scatter plot, trend line and confidence intervals? * * 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/ |
In reply to this post by Joseph Coveney
Thank you Joseph. I am in the process of programing and testing Sokal and Rohlf which also uses the Q statistic. I am using John Gleason's -qsturng- command for the distribution. I would be intereted in seen if they are both the same method.
Regards, Ricardo Ricardo Ovaldia, MS Statistician Oklahoma City, OK --- On Tue, 3/16/10, Joseph Coveney <[hidden email]> wrote: > From: Joseph Coveney <[hidden email]> > Subject: st: Re: Post-Hoc test for Kruskal Wallis > To: [hidden email] > Date: Tuesday, March 16, 2010, 6:52 AM > Ricardo Ovaldia wrote: > > Is there a Post-Hoc test for Kruskal Wallis in Stata? > Something like the one proposed by Sokal and Rohlf (1995). > > -------------------------------------------------------------------------------- > > I'm not sure whether it's the same test that you're > referring to, but last > summer I had an occasion to program the Dwass, Steel, > Critchlow-Fligner test. I > used M. Hollander & D. A. Wolfe, _Nonparametric > Statistical Methods_ Second > Edition. (New York: John Wiley & Sons, 1999) pp. > 240--44 as the source for the > formula and for the worked example to verify the ado file's > output. > > It's not difficult to program, but I'll put it up on SSC > once I write a help > file. You'll need to install John Gleason's -qsturng- > from SSC in order to get > the reference distribution for the test statistic > (Studentized range) if you > want to avoid manual look-up. > > Joseph Coveney > > > * > * 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/ |
In reply to this post by Nick Cox
Thanks Nick and Jeph for your replies
Nick Cox wrote: I think the main trick is to keep all the locals you need together with the graph commands in a _small_ .do file. That is, as a .do file can call other .do files, storing definitions together with commands is the most obvious way to go. I agree but in my work I have to do a lot of "mass production" where the output is nearly the same for a lot of customers. So I often end up with huge do-files and loops. There might be other ways but despite the issue discussed here I'm quite comfortable with that. Jeph Herrin wrote a script to show that locals and contents of locals can be parsed from -macro list-. The idea works well but in this form only for simple locals. I have some special cases so I altered it according to them: There are issues with long locals going over several rows in -macro dir-. I decided to take only the local names from -local dir- and take the content right out of the local. I often have several parts each containing several numbers or words in compound quotes in one local (e.g. different graph titles). After a linebreak in -macro dir- it could happen that something like 2007"' was the first word and caused errors in the -stringpos- function even if compound quotes in -stringpos- were used. I eliminated all quotes from the first word of each line. Here's the altered script: It worked with all of my locals but I'm not sure if it can handle each and every special case. ********** capture log close log using mylocals2.txt, text replace macro list log close file open logfile using mylocals2.txt, text read file open mylocals using mylocals2.do, text replace write file read logfile line while r(eof)==0 { local lname : word 1 of `line' local lname : subinstr local lname `"""' "" local lname : subinstr local lname `"'"' "" if strpos("`lname'","_")==1 { local lval : subinstr local line "`lname'" "" local lname : subinstr local lname "_" "" local lname : subinstr local lname ":" "" file write mylocals "local `lname' " _char(34) `"``lname''"' _char(34) _n } file read logfile line } file close logfile file close mylocals ********** Thanks again Stefan * * 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/ |
In reply to this post by Nick Cox
I agree that "mark&find" is a nice feature but as far as I know
it's not documented (PDF-documentation GSW[13] paragraph "searching"). Different software uses this in different ways so the user never knows. One can argue that - after the search box is closed - the search ends and F3 provides an additional search function based on the last inserted or marked string. But on the other hand F3 is named "Find Next" which makes it a logical successor of "Find". In general it would be better not to have a search box but a search field in the top or bottom of the editor GUI (e.g. like in Firefox or Acrobat reader) which shows the active search string to the user and doesn't interfere with the text window. Stefan * * 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/ |
<> " but a search field in the top or bottom of the editor GUI (e.g. like in Firefox or Acrobat reader)" Or in the Viewer shipped with Stata - where the F3 key, in turn, seems not to be functional... HTH Martin -----Ursprüngliche Nachricht----- Von: [hidden email] [mailto:[hidden email]] Im Auftrag von [hidden email] Gesendet: Mittwoch, 24. März 2010 10:55 An: [hidden email] Betreff: st: Find Again and Copy in do-file editor I agree that "mark&find" is a nice feature but as far as I know it's not documented (PDF-documentation GSW[13] paragraph "searching"). Different software uses this in different ways so the user never knows. One can argue that - after the search box is closed - the search ends and F3 provides an additional search function based on the last inserted or marked string. But on the other hand F3 is named "Find Next" which makes it a logical successor of "Find". In general it would be better not to have a search box but a search field in the top or bottom of the editor GUI (e.g. like in Firefox or Acrobat reader) which shows the active search string to the user and doesn't interfere with the text window. Stefan * * 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/ |
In reply to this post by Nick Cox
Dear Johan,
length of election period is an issue in this calculation. If you have the length of the election period you can turn the proportional time-var into an absolute time var. Perhaps you can take the length of the election period from the start and end dates of governments that didn't fail (Assuming that election periods remain constant over time in one country). That's the easy part. Time to the next election seems to be quite of importance for government action so it might influence the failure risk years before the election period ends. So you probably have time-independent risk factors (political events, affairs), time-dependent risk factors from the start (wear, growing animosities in a coalition) and time-dependent risk factors towards the end (tactical behavior of reelection favourite, ending of a stalemate situation). So if one election period is four and another is five years it's probably not done only by censoring at four years. Stefan *********** Dear Stata-users, I have question regarding how to set up failure-time data in Stata. In my dataset (an unbalanced panel of data on governments from 1945-2009) I have a proportional time-variable, i.e. the relative duration time measuring if government cabinets survives a whole term for which is elected, where 1 indicates that is stays in power for a whole term and e.g. 0.5 the cabinet dissolves after half a term. It is possible to use such a variable for setting up failure-time data in Stata? I also have the start date and end date of cabinets, but since the time-variable above also contains qualitative judgements (of experts) what constitutes an failure, e.g. as some countries does not have fixed terms, it would be appropriate to use the relative duration variable described above. Thanks, Johan Hellström * * 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/ |
In reply to this post by Stefan.Gawrich
This seems to be a character encoding error. See:
http://en.wikipedia.org/wiki/Character_encoding Different Software may use different encodings. I don't find the example text string on the net so I can't guess the character encoding involved. There are translation routines available (e.g. see Wikipedia article or some database software) which may be the most secure way to handle this. If you're sure that only a few characters have to be translated, the manual conversion might be the easiest solution. Stefan Testing german umlauts on the list: ü - ä - ö - ß (ue - ae - oe - sharp-s) * * 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/ |
In reply to this post by Stefan.Gawrich
Stefan,
Thanks' for the help. Best, Johan * * 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/ |
In reply to this post by Nick Cox
Dear Markus,
thanks for -ebrowse-. As far as -viewsource- tells me you have set the version to 9 which causes c(version) to be set to 9 which makes "if (c(version)>=11) {" quite predictable. With version set to 11 it works for me. Stefan * * 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/ |
Dear Stefan
thank you for the hint. This version statement should not be there. Just added it last minute and submitted it without checking it properly. Submitted an updated version to ssc. Cheers Markus --- Dear Markus, thanks for -ebrowse-. As far as -viewsource- tells me you have set the version to 9 which causes c(version) to be set to 9 which makes "if (c(version)>=11) {" quite predictable. With version set to 11 it works for me. Stefan * * 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/ |
In reply to this post by Nick Cox
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/ |
<> 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: [hidden email] [mailto:[hidden email]] Im Auftrag von [hidden email] Gesendet: Donnerstag, 15. April 2010 12:26 An: [hidden email] 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/ |
In reply to this post by Nick Cox
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 * * 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/ |
Free forum by Nabble | Edit this page |