Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | "Michael N. Mitchell" <Michael.Norman.Mitchell@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: date("01jan1960", "DMY") does not seem to work with -if- qualifier of the command -tablist- |
Date | Mon, 21 Mar 2011 18:47:14 -0700 |
Dear JeremyThis 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/