Statalist The Stata Listserver


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

st: RE: RE: RE: RE: tabodds command with 'if' option


From   "Visintainer, Paul" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: RE: RE: tabodds command with 'if' option
Date   Tue, 7 Mar 2006 21:42:48 -0500

Thanks, Nick.  While I certainly was fond of the -for- command, no one
wants to be labeled a dinosaur!

-p



______________________________
Paul F. Visintainer, PhD
Professor and Chairman 
Department of Epidemiology and Biostatistics
School of Public Health
New York Medical College 
Valhalla, NY  10595
PH: (914) 594-4804
FX: (914) 594-4853

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Nick Cox
Sent: Tuesday, March 07, 2006 11:11 AM
To: [email protected]
Subject: st: RE: RE: RE: tabodds command with 'if' option

StataCorp made this decision some time ago and I see no chance of them 
reversing it. 

There was some discussion in 

SJ-3-2  pr0009  . . . . . . . . . . . . . Speaking Stata:  Problems with
lists
        Q2/03   SJ 3(2):185--202                                 (no
commands)
        discusses ways of working through lists held in macros

SJ-2-2  pr0005  . . . . . .  Speaking Stata:  How to face lists with
fortitude
        Q2/02   SJ 2(2):202--222                                 (no
commands)
        demonstrates the usefulness of for, foreach, forvalues, and
        local macros for interactive (non programming) tasks

Neither is an "official" statement, but nevertheless there they are. 

Here are some extracts from the 2003 paper. This was my original text
before translation from English into American. It naturally predates
the introduction of Mata's -for-, which makes it even less likely that
the old -for- will come back, Elvis-like. 

========================================================================
======
If you used Stata 7, or some
previous version, then quite possibly the demise of -for- will have been
a small piece of bad news for you. 
 
Strictly, demise is as yet too strong a word. More precisely, -for- is
no longer on display as part of the official Stata repertoire. The code
is still there, and if you used -for- in your do files or programs they
should still work in Stata 8: if they do not work, it will be for some
other reason. But the on-line help and the manual entry have gone, so
for either or both of those you must depend on whatever is accessible to
you from previous versions. This is not prohibition, but it certainly
amounts to discouragement. -for- is history, and you are best advised to
make greater use of the alternatives, particularly if you imagine using
Stata for some time to come. More than that, do not count on -for- as
you knew it being around for ever, even undocumented or under version
control. 
 
Why has this been done, particularly in view of Stata's longstanding
commitment to maximising continuity from release from release? -for- has
long served many users well. Some regard it as one of their favorite
commands. But it has severe limitations, several of which were rehearsed
in a previous column (Cox 2002) [cited above]. I will mention here just
three. 
 
First, -for- was, frankly, idiosyncratic and did not mesh well with the
rest of Stata. Particularly limiting was the fact that it could not make
use of local or global macros in the ways that might be expected. There
was no deep-seated bug here, and -for- was not behaving differently from
other Stata commands in this respect; merely its behavior often clashed
with users' preconceptions of how it should behave. 
 
Second, once -for- had been learned by many users, they often tried to
build in multiple loops and multiple commands. For all sorts of reasons,
this often did not work.  -for- was just not strong enough to bear the
weight which some users tried to put on it. This was not because the
code was incompetently written; it is just too difficult a task to
handle what were in one sense complete programs codified as just one
command line. Even when -for- did work, the resulting code was often
difficult to read, to understand or to revise. Users were thus being
tempted into bad habits because of the features which -for- appeared to
offer. 
 
Third, -for- was slow. Frequently that was not obvious to users because
of the speed of Stata and of their computers, but -for- was implemented
as interpreted code, thus imposing an overhead.  One of the main
characteristics of the new commands -foreach- and -forvalues-
introduced in Stata 7 is that they are implemented as compiled code and
so run much faster. 
 
-foreach- and -forvalues-, new in Stata 7, are now the main
workhorses for looping through lists. If these are new to you, apart
from the on-line help, see [P] foreach and [P] forvalues.
You may need to supplement those with some reading on local macros,
particularly within [U] 21. These references do not mean that you
have to write Stata programs to be able to use these constructs. On the
contrary, they are often used interactively and you can incorporate them
in do files or code you run from the do file editor. 

(Once again, what is a Stata program?  Simply, whatever is defined by a
Stata -program- command. [...]) 

For Stata programming, -while- was the main workhorse in previous
versions, and it is still useful for some problems. For interactive use,
-for- was the main workhorse in previous versions, but as said its use
is now officially discouraged. 
===================================================================

Nick 
[email protected] 

Visintainer, Paul
 
> why is the -for- command being dropped?  Obviously 
> -forval- and -foreach- are far more flexible, but the -for- 
> command is quite convenient in routine data manipulation and 
> analysis.  Its a great way to introduce new students to 
> looping over numbers or variables.  I would vote for retaining it.

Nick Cox
  
> unless the user has an old version of Stata, no
> on-line help is now available for -for-. 
> 
> For reasons documented elsewhere, -for- is in 
> essence deprecated. -forval- and -foreach- 
> should be considered preferable. 
 
Visintainer, Paul
  
> > Assuming your data are set up appropriately, try:
> > 
> > for num 1/5: tabodds case year [fweight=freq] if cat == X
 

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

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