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]
Re: st: date("01jan1960", "DMY") does not seem to work with -if- qualifier of the command -tablist-
From
Jeremy Page <[email protected]>
To
[email protected]
Subject
Re: st: date("01jan1960", "DMY") does not seem to work with -if- qualifier of the command -tablist-
Date
Thu, 31 Mar 2011 12:04:05 -0400
I followed up the Stata technical support and they have indicated that
this behavior was not intended. They have forwarded this issue onto
their development team and they will address it in a future update. I
want to thank Michael Mitchell and Nick Cox for their help in tracking
down the root of the issue.
Best,
Jeremy
On Tue, Mar 22, 2011 at 5:05 AM, Nick Cox <[email protected]> wrote:
> Michael Mitchell's -tablist- is similar in spirit to my -groups-
> (SSC). (I am not sure that either of us has registered that before
> now.)
>
> FWIW, -groups- behaves similarly on this example:
>
> . groups bday name if statadate > date("01Jan1960", "DMY")
> ---------------------------------------------------------------------
> begin groups ---
> - version 8
> - syntax varlist [if] [in] [fweight aweight/] [, NOObs SUBVARname SUM
> Compress LABvar(
>> varname) * FILLin MISSing SHow(str) showhead(str asis) SELect(str) Order(str) FORMat
>> (str) nby(numlist int >0) ge lt REVerse ]
> - if "`missing'" == "" marksample touse, strok
> = if "" == "" marksample touse, strok
> - else marksample touse, novarlist
> - qui count if `touse'
> = qui count if __000001
> - if r(N) == 0 error 2000
> no observations
> -----------------------------------------------------------------------
> end groups ---
> r(2000);
>
> Under version control the new syntax of -date()- is treated within
> -marksample- as legal, but it yields missings.
>
> Nick
>
> On Tue, Mar 22, 2011 at 5:40 AM, Kieran McCaul <[email protected]> wrote:
>> ...
>>
>>
>> The old date function syntax used "dmy" not "DMY".
>> I think you'll find that the following works:
>>
>> tablist bday name if statadate > date("01Jan1960", "dmy")
>>
>>
>>
>>
>> -----Original Message-----
>> From: [email protected]
>> [mailto:[email protected]] On Behalf Of Michael N.
>> Mitchell
>> Sent: Tuesday, 22 March 2011 9:47 AM
>> To: [email protected]
>> Subject: Re: st: date("01jan1960", "DMY") does not seem to work with
>> -if- qualifier of the command -tablist-
>>
>> Dear Jeremy
>>
>> This is a most curious issue! Eric provides an excellent solution,
>> but I was still
>> flummoxed why the behavior of the -if- condition should be different for
>> my -tablist-
>> command as compared to a command like -tabulate-. So, I investigated.
>>
>> The heart of -tablist- is the -contract- command. The -if-
>> specification is passed from
>> -tablist- to -contract-, and then within the -contract- command it is
>> being implemented
>> via the -marksample- command. So I tested the -marksample- command using
>> your if condition.
>>
>> . clear
>> . use http://www.stata-press.com/data/r10/datexmpl.dta
>> . gen statadate = date(bday, "DMY")
>> . format statadate %td
>> . local if statadate > date("01Jan1960", "DMY")
>> . marksample touse, strok novarlist
>> . list
>>
>> +------------------------------------------------+
>> | name bday x statadate __000004 |
>> |------------------------------------------------|
>> 1. | Bill 21 Jan 1952 22 21jan1952 0 |
>> 2. | May 11 Jul 1948 18 11jul1948 0 |
>> 3. | Sam 12 Nov 1960 25 12nov1960 1 |
>> 4. | Kay 9 Aug 1975 16 09aug1975 1 |
>> +------------------------------------------------+
>>
>> The temporary variable __000004 properly indicates that Sam and Kay were
>> born after
>> 1/1/1960. But, if you look inside the source code of the -contract-
>> command using
>> -viewsource contract.ado-, you can see that it is running under version
>> control, using
>> -version 6.0-. So, let's try this again, but running the -marksample-
>> command under
>> version control.
>>
>> . version 6.0, missing : marksample touse, strok novarlist
>> . list
>>
>> +-----------------------------------------------------------+
>> | name bday x statadate __000004 __000005 |
>> |-----------------------------------------------------------|
>> 1. | Bill 21 Jan 1952 22 21jan1952 0 0 |
>> 2. | May 11 Jul 1948 18 11jul1948 0 0 |
>> 3. | Sam 12 Nov 1960 25 12nov1960 1 0 |
>> 4. | Kay 9 Aug 1975 16 09aug1975 1 0 |
>> +-----------------------------------------------------------+
>>
>> The new variable created, -__000005-, believes that none of these
>> children were born after
>> 1/1/1960.
>>
>> Unfortunately, we cannot trace this any deeper because the
>> -marksample- command is a
>> built in command.
>>
>> I think if the -marksample- command (within the -contract- command)
>> were issued using
>> version control to bring it to the current version, then I believe that
>> the behavior of
>> -contract- with the kind of -if- condition you used would then be
>> consistent across commands.
>>
>> Best regards,
>>
>> Michael N. Mitchell
>> Data Management Using Stata -
>> http://www.stata.com/bookstore/dmus.html
>> A Visual Guide to Stata Graphics -
>> http://www.stata.com/bookstore/vgsg.html
>> Stata tidbit of the week - http://www.MichaelNormanMitchell.com
>>
>>
>>
>> On 2011-03-21 5:22 PM, Jeremy Page wrote:
>>> I am a frequent user of the user generated command -tablist- and I
>>> have run into a behavior that I can not explain. I am trying to use
>>> Stata's -date- command with the -if- qualifier to restrict
>>> observations from displaying in -tablist-. When I attempt to do this
>>> there appears to be a problem. I am able to use the -date- command to
>>> restrict observations with -tabulate- and I am able to restrict
>>> observations in -tablist- with a local variable being defined by the
>>> -date- command but not with -tablist-. It is my understanding that
>>> the -if- qualifiers across all programs should act the same. Am I
>>> missing something? I have included an example below using a Stata
>>> supplied data set.
>>>
>>> I am using version 1.2 of -tablist- which can be found at -findit
>>> tablist- and my version of Stata is 10.1 on a Windows XP machine.
>>>
>>> Thank you for your help.
>>>
>>> Best,
>>> Jeremy
>>>
>>>
>>>
>>> **********begin example***************
>>> clear
>>> use http://www.stata-press.com/data/r10/datexmpl.dta
>>>
>>>
>>> gen statadate = date(bday, "DMY")
>>>
>>> format statadate %td
>>>
>>> list statadate
>>>
>>> display date("01Jan1960", "DMY")
>>>
>>> ***it works with tabulate
>>> tab bday name if statadate> date("01Jan1960", "DMY")
>>>
>>>
>>> ***it works with a local variable
>>> local dte = date("01Jan1960", "DMY")
>>> tablist bday name if statadate> `dte'
>>>
>>> ***it does not work with tablist
>>> tablist bday name if statadate> date("01Jan1960", "DMY")
>>>
>>>
>>> ************end example***************
>>>
>
> *
> * 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/