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: If-command not accurate

From   Nick Cox <>
To   "" <>
Subject   Re: st: If-command not accurate
Date   Tue, 7 Aug 2012 17:43:49 +0100

Your title is misleading. You need

if "'var'" == "PF_ret6" {

(there doesn't seem to be a single left quotation mark on the device I am using). You are looking for a match on names, not values.


On 7 Aug 2012, at 17:26, "Daniel Brodback" <> wrote:

Dear all,

in a foreach-loop, I am trying to "catch" a specific case and therefore I implement this with an if-command.

For my varlist, I want certain commands to be executed but when var "PF_ret6" occurs, I need different commands.

I implemented this in the following way (Stata SE 11.2):

foreach var of varlist PF_dy-PF_ret6 {
   if `var' == PF_ret6 {

The weird behavior is, that for the first variables everything works as expected. But when the variable prior to PF_ret6 is reached (named PF_lret6), it also enters the if-condition.
Is there a way to assure that the if-command only uses PF_ret6 but not
*   For searches and help try:

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