Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: a loop error of -foreach-


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   RE: st: a loop error of -foreach-
Date   Mon, 20 Sep 2010 10:17:10 +0100

This isn't quite correct. 

If you have a string variable -foo- which you wish to compare with some literal string, then its variable name should _not_ be quoted. Given also a macro with name -bar-, then 

if foo == "`bar'" 

and 

if "foo" == "`bar'" 

are quite different constructions for quite different comparisons. The only circumstance in which the two yield the same results is if the variable -foo- happens to contain the string "foo", and similarly for other examples. 

Nick 
[email protected] 

Sarah Edgington
===============

Go with the previous suggestion of :

if "`j'" == "b" { 

I think that will work even if b is the name of a variable because you're
telling stata to check whether the local macro j is equal to the string "b"
rather than equal to the value of the variable b.

Grace Jessie
============

More exactly, I want to do -reg b x1 x2- if `j' gets the value of b,and do
-logit a/c/d x1 x2- otherwise, where x1 and x2 are independent variables.
I just want to take the lists as elements and then do different things,i.e.,
do different things for different elements in the lists.
 

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


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index