Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

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

RE: st: a loop error of -foreach-

From   Nick Cox <>
To   "''" <>
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'" 


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. 


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:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index