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: Use extended functions outside of macro assignment?


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Use extended functions outside of macro assignment?
Date   Wed, 7 Sep 2011 08:41:51 +0100

The second example problem looks like one of selecting observations. I
think all ways of doing that reduce to a condition on the values of
some variable(s) to be given explicitly.

The first mentioned -regexm()-. Note that neither -ds- or -findname-
offers a direct way of using -regexm()-. I think you would need to
loop over variables, selecting those satisfying your -regexm()- call
and build up a macro containing a varlist that way. That's the small
trick used repeatedly inside -ds- and -filename-. As far as -findname-
is concerned, I drew short of building in that functionality because I
haven't needed it yet for myself and the syntax is already rather
complicated. And I knew of the way to do it just mentioned. (-ds- I
think all predates -regexm()-.)

On Wed, Sep 7, 2011 at 7:06 AM, Nick Cox <[email protected]> wrote:
> The logic of -list- with -if- is like any other command. Consider
>
> list if 2 == 2
>
> 2 == 2 is (vacuously) true when considered for observation 1, for
> observation 2, and so on, so every variable and every observation will
> be -list-ed. The same will be true of your syntax. If your condition
> is true, i.e. there is a match, then everything will be listed.
>
> What I think you want is a two-step operation to Stata. First, you
> produce a varlist, then you supply that varlist to some command. In
> official Stata, check out -ds- and in user-written Stata check out
> -findname-. -search findame- in an up-to-date Stata will find an
> article and an update in the Stata Journal; use the update to get the
> software and read the article!
>
> Nick
>
> On Tue, Sep 6, 2011 at 9:06 PM, James Sams <[email protected]> wrote:
>> I keep running into situations where I would like to use an extended function
>> as a part of a function call, e.g. in a conditional statement. I thought I had
>> seen syntax to do this before, but I cannot find this now.
>>
>> For example, let's say I wanted to operate on a set of observations dependent
>> upon some characteristic of a value label, say that the value label matches
>> some regular expression. How can I do this? I specifically cannot pull the value
>> label into a string variable with decode due to the size of the dataset:
>>
>> Something like this:
>> list if regexm("`: label (varname)'", "my_regex")
>>
>> or say I want to operate on a set of ids I have stored in a local macro "ids":
>>
>> list if `: list posof id in ids'
>
*
*   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