Bookmark and Share

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

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

Re: st: flagging significant values in a variable

From   Partho Sarkar <[email protected]>
To   [email protected]
Subject   Re: st: flagging significant values in a variable
Date   Sun, 4 Mar 2012 10:00:28 +0530

Fair enough, Nick.  Especially appreciate your elegant one line cond()
code-  I have struggled with this useful but arcane function in the
past!  I still think, though, that the "tolerance" threshold is a
natural interpretation of the phrase " *significantly*  higher/lower"
-it certainly came to my mind quite naturally!

By the way, if I may harp on the side issue of duplicate threads once
more, I (like many others, perhaps) don't get all Statalist posts
mailed to me (unless they are in response to one of my own posts) but
view the archive occasionally, and respond if I see something that I
want to respond to.  So my mailer is not really at fault here!  This
makes such "instances" of oversight of earlier replies much more
likely if a question is posted twice on separate threads (that happens
fairly often).   I wonder if it would be feasible/cost-effective to
put in  place a mechanism to prevent this (beyond asking listers to
observe care in posting).


On Sat, Mar 3, 2012 at 11:05 PM, Nick Cox <[email protected]> wrote:
> Threading is what your mailer does. It's not inherent in Statalist's
> operation. (Archiving is a separate matter.)
> But that's of no consequence: we all overlook previous emails from
> time to time.
> On the question of introducing a tolerance to the question, I stand by
> my earlier comment.
> If I understand you correctly the code you posted earlier was really
> intended as a code sketch and readers were expected to be perceptive
> enough to realise that. That really wasn't clear to me. I would be
> surprised if it was clear to anybody else But let's concentrate on the
> code and spell out what your approach implies, a loop over
> observations.
> forval i = 1/`=_N'
>        if lci[`i'] - natlci[`i'] >`tol' {
>               replace tag=1 in `i'
>       }
>       else if lci[`i']-natlci[`i'] < -`tol' {
>               replace tag= 2 in `i'
>      }
>      else {
>              replace tag = 0 in `i'
>     }
> }
> However, this loop really isn't necessary as the whole thing can be
> done in one line.
> replace tag = cond(lci - natlci >`tol', 1, 2 * (lci[`i']-natlci[`i'] < -`tol'))
> If that's over-compressed, there is a shorter version in about three
> lines, similar in spirit to Graham's posting yesterday. That will be
> much faster.
> If you want to prefer a loop over observations here, that's your prerogative.
> (To concentrate on one specific code question, I have left in your tolerance.)
> Nick

*   For searches and help try:

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