Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Order


From   "Austin Nichols" <[email protected]>
To   [email protected]
Subject   Re: st: Order
Date   Tue, 12 Jun 2007 22:39:53 -0400

Thomas Speidel--
The -capture- command does not work any magic you want it to. It
simply suppresses any error messages, so a command that fails to run
and returns an error will still fail to run when preceded by -cap-.
What you want to do is put together a list in a -local- of the
variables that exist in your data, e.g.
clear
set obs 10
gen Sector=1
gen Feb2007=2
gen Dec2006=6
gen Oct2006=4
gen Nov2006=84
gen Sep2006=897
gen Jan2007=4.3
local oklist
forv y=2005/2009 {
foreach m in `c(Mons)' {
 cap ds `m'`y'
 if _rc==0 local oklist `oklist' `m'`y'
}
}
order `oklist'
d

On 6/12/07, Thomas Speidel <[email protected]> wrote:
I am trying to order the variables of a dataset in a chronological
fashion (the month+year is stored in the the varname - the content of
the variables is _not_ a date).   I have to allow for the possibility of
additional variables reflecting future/past dates, hence the lengthy
order command.  I am not sure why this is happening, since I thought the
capture option should take care of it, but the following code does not
produce what I had expected:

set obs 10
gen Sector=1
gen Feb2007=2
gen Dec2006=6
gen Oct2006=4
gen Nov2006=84
gen Sep2006=897
gen Jan2007=4.3
capture order Sector Jan2006 Feb2006 Mar2006 Apr2006 May2006 Jun2006
Jul2006 Aug2006 Sep2006 Oct2006 Nov2006 Dec2006 Jan2007 Feb2007 Mar2007
Apr2007 May2007 Jun2007 Jul2007 Aug2007 Sep2007 Oct2007 Nov2007 Dec2007
Jan2008 Feb2008 Mar2008 Apr2008 May2008 Jun2008 Jul2008 Aug2008 Sep2008
Oct2008 Nov2008 Dec2008
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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