Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Double loops


From   "Jonas Dahlqvist" <[email protected]>
To   <[email protected]>
Subject   Re: st: Double loops
Date   Thu, 02 Dec 2004 16:39:24 +0100

Indeed, saved but not one but two Nicks. Puns apart, your suggestions  worked as I hoped they would. The code after the open brace was probably the culprit along with "a little knowledge" (the kind  that is a dangerous thing). Many thanks to you both. Data dredging here I come.

Sincerely,

Jonas Dahlqvist

Jonas Dahlqvist

J�nk�ping International Business School
Box 1026
SE-551 11 J�nk�ping
SWEDEN

Office phone: +46 36 157547
Office fax: +46 36 161069
Local time: GMT +1

>>> [email protected] 2004-12-02 15:51:36 >>>
I believe that there were conditions under hwich Stata 7 would crash, when 
there was code following on the same line after an open brace ( "{" 
).  THis is why, I think, Stata 8 does not allow that usage.

So you might try something like this:

foreach nvar of varlist var1 var2 var3 var4 {
    foreach X of varlist var5 var6 {
      quietly tab `nvar' `X', all
      if r(p)<0.05 {
         display "Significant at the 5% level: `nvar' `X' p=" r(p) " / " 
r(p_lr)
      }
    }
}

--Nick Winter



At 03:27 PM 12/2/2004 +0100, you wrote:
>Using Stata 7
>I am trying to run two loops of varlists simultataneously. Dual "foreach" 
>crashed the program (that was a first!) so I settled for a "for" loop 
>within a "foreach" loop. My ignoble little interactive program looks like this:
>
>foreach nvar of varlist var1 var2 var3 var4 {for X in var var5 var6: 
>quietly tab `nvar' X, all\
>if r(p)<0.05 {display "Significant at the 5% level: `nvar' `X' p=" r(p) " 
>/ " r(p_lr)}}
>
>This program is admittedly a crude stab at data exploration, directly from 
>the Boys own book of statistical horrors. Nevertheless, my problem is that 
>I cannot get the variable from the "for" loop to print out properly. What 
>I want Stata to do is to print the name of row and column variables from a 
>simple crosstab along with the associated chi-square probabilities if the 
>the p-values are under some specified level. Such as:
>
>"Significant at the 5% level: var1 var4 p=0.047 / 0.049"
>
>As it stands, I cannot get the name of the variable used in the "for" loop 
>to print.
>
>Is there a more elegant way of doing this (that works)?
>
>Sincerely,
>
>Jonas Dahlqvist
>J�nk�ping International Business School
>Sweden
>
>
>
>*
>*   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/ 

--------------------------------------------------------
Nicholas Winter                           607.255.8819 t
Assistant Professor                       607.255.4530 f
Department of Government              [email protected] e
308 White Hall            falcon.arts.cornell.edu/nw53 w
Cornell University
Ithaca, NY 14853-4601 



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