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


From   Kyle Peyton <kyle.peyton@unimelb.edu.au>
To   "<statalist@hsphsun2.harvard.edu>" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Identifying complicated varlist for foreach loop
Date   Sat, 16 Jul 2011 04:01:03 +0000

Thanks Nick, that did the trick! 


On 15/07/2011, at 1:07 PM, "Nick Cox" <njcoxstata@gmail.com> wrote:

> 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/
> 


*
*   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