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 at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: If-command not accurate


From   "Daniel Brodback" <schmani@gmx.de>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: If-command not accurate
Date   Tue, 07 Aug 2012 18:43:06 +0200

Dimitriy,

you are right. I did not know this notation yet. Thank you very much for your quick help, much appreciated!

Best,

Daniel

-------- Original-Nachricht --------
> Datum: Tue, 7 Aug 2012 09:34:21 -0700
> Von: "Dimitriy V. Masterov" <dvmaster@gmail.com>
> An: statalist@hsphsun2.harvard.edu
> Betreff: Re: st: If-command not accurate

> You are misunderstanding how if works. This is a common misconception.
> The first pass through the loop, the condition "if PF_dy == PF_ret6"
> means if the first observation of PF_dy equals PF_ret6, do some stuff.
> You probably want -if "`var"=="PF_ret6" {-. This does the string
> comparison you had in mind.
> 
> DVM
> 
> On Tue, Aug 7, 2012 at 9:26 AM, Daniel Brodback <schmani@gmx.de> 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 {
> > ...
> > }
> > else
> > {
> > }
> > }
> >
> > 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
> PF_lret6?
> >
> > Kind regards,
> >
> > Daniel
> > *
> > *   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/
> *
> *   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/
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index