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

st: Double loops


From   "Jonas Dahlqvist" <[email protected]>
To   <[email protected]>
Subject   st: Double loops
Date   Thu, 02 Dec 2004 15:27:42 +0100

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/



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