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: Identifying complicated varlist for foreach loop


From   Nick Cox <njcoxstata@gmail.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Identifying complicated varlist for foreach loop
Date   Fri, 15 Jul 2011 04:05:07 +0100

unab vvars: v*
foreach v of local vvars {
            local stub = substr("'v",2,.)
            local stubs 'stubs' 'stub'
}

is one way to do it, it being understood that ' ' should really be left single quote and right single quote.

Nick




On 15 Jul 2011, at 02:45, Kyle Peyton <kyle.peyton@unimelb.edu.au> wrote:

Hi all,

I have a very large dataset with some variables that I suspect have matching observations. I want to test this expectation and eliminate superfluous variables.

Essentially, I have two groups. In group 1, all variables have a prefix of "v". So we might have Vpen, Vshirt, Vfrog, etc. Let's assume I have 100 variables in group 1, all of them having this prefix "v"

In group 2, I have approximately 250 variables. Of those 250 variables, 100 variables are the same as those in group 1, minus the prefix. The other 150 I am certain are different. So we would have pen, shirt and frog, etc. My expectation (hope) is that this is the case and then I will be able to simply drop the variables with the "v" prefix from my dataset.

Is there a way to identify the SUFFIX of everything with a v PREFIX and then define that as a list? Then I'm thinking I can create a loop along these lines:

Foreach x in varlist (this is the varlist of my 100 important variables, my non-prefixed pens and frogs, etc.)
Assert `x' = v`x' (assuming this  RHS works !)

This could be the completely wrong logic, however.
*
*   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