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: Loop to compare several variables within different timepoints


From   Nick Cox <njcoxstata@gmail.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Loop to compare several variables within different timepoints
Date   Sun, 2 Feb 2014 11:34:19 +0000

My code makes no assumptions about the exact number of variables, so
it would not change.

Nick
njcoxstata@gmail.com


On 2 February 2014 11:29, Nikolaos Pandis <nikpandis@gmail.com> wrote:
> I completely agree with your  initial comment-this was more of an exercise.
> How would the code change if we assume that the exact number of variables is 25?
> Thank you,
>
> Nick
>
> On Sun, Feb 2, 2014 at 12:52 PM, Nick Cox <njcoxstata@gmail.com> wrote:
>> Statistically, this sounds dubious and unsound: the tests are not
>> independent and the shotgun approach raises questions about your
>> interpretation of the resulting P-values.
>>
>> Focusing on the Stata question, which is of some wider interest:
>>
>> If your variables were just a1, a2, a3, ..., c1, c2, c3 you could go
>>
>> foreach v in a b c {
>>       signrank `v'1 = `v'2
>>       signrank `v'3 = `v'2
>> }
>>
>> so this just raises the question of how to extend "a b c" to whatever
>> stubs you have. Your description of variable names is too vague
>> ("about 25 variables") to imply exact code, but this shows one trick:
>>
>> unab stubs : *1
>> local stubs : subinstr local stubs "1" "", all
>>
>> That would reduce (e.g.)
>>
>> a1 b1 c1 d1 e1 f1 g1 h1 i1 j1
>>
>> to
>>
>> a b c d e f g h i j
>>
>> after which the code would be
>>
>> foreach v of local stubs {
>>       signrank `v'1 = `v'2
>>       signrank `v'3 = `v'2
>> }
>>
>> Nick
>> njcoxstata@gmail.com
>>
>>
>> On 2 February 2014 10:38, Nikolaos Pandis <nikpandis@gmail.com> wrote:
>>> I have about 25 variables for  which I recorded outcomes at 3 times
>>> points (t1, t2, t3)
>>> I  would like to construct a loop where I can automate testing using
>>> the "signrank" test
>>>
>>> I would like to do the following:
>>>
>>> signrank a1=a2
>>> signrank b1=b2
>>> signrank c1=c2
>>> .....
>>> signrank a3=a2
>>> signrank b3=b2
>>> signrank c3=c2
>>> ..............
>>>
>>> a,b,c are the variables and 1,2,3 refer to the timepoints
>>>
>>> I am only interested in 25*2=50 comparisons and not to compare
>>> different letter variables between them. Only within the same
>>> variables to compare between timepoints.
>>>
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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