[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Martin M. Monti" <mmonti@Princeton.EDU> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: Scripting Question |

Date |
Fri, 29 Apr 2005 11:39:11 -0400 |

Hi Everyone,

I'm trying to write a .do file that may scroll through my variables performing simple tabstats and ttests on pairs of variables. The key variables to test/tabstat are identified by a string (e..g "judged") and an appended number (thus: e..g judged1, judged2, ...). A simple loop on an `i' macro will allow me to specify judged`i' in the loop and have it scroll through the various variables, but when I set a second macro (say `k') making it equal to `i'+1 (so that I can always do ttestes on variables in sequence (e.g. ttest time`i' = time`k' so that it's always "ttest time1 = time2", "ttest time3 = time4", and so on)) even though it will loop through the correct numbers (thus `k' is correctly being set to `i'+1), it will not allow me to append it to the string (unlike `i'!).

Here is the loop I use:

*the loop only sets `i' to odd numbers (so that `k' can scroll through the even ones)

forvalues i = 1 (2) 7 {

foreach k in `i'+1 {

table judged`i' judged`k'

tabstat time`i' time`k', stats(mean sd N)

ttest time`i' = time`k' if (judged`i' == 1 & judged`k' == 1)

tabstat rate`i' rate`k', stats(mean sd N)

ttest rate`i' = rate`k' if (judged`i' == 1 & judged`k' == 1)

}

}

Note, I''ve tried running the loop and the problem is that as it is supposed to execute the commands with `k' it will say that the variable judged (only with the `k' appended!) is ambiguous. Also, if I run the same exact loop, just replacing the 5 commands with only: display `i' and display `k' it will scroll correctly through the numbers.

Inpupt will be appreciated!

Cheers,

Martin

--------------------------------------------

Test: Are you a true psychology researcher?

A couple of famous psychologists have twins. They call one Mike, and the other... Control.

(if this joke makes you laugh then yes, you are)

"This Quantum Physics thing that time is the same thing as space I

just don't get it. So what if I walk up to someone and ask 'what time is it?'

What does he answer? '....6 miles?'" [Woody Allen]

--------------------------------------------

Martin M. Monti

Princeton University

Department of Psychology

Green Hall 3-S-7

(609) 258-4480

--------------------------------------------

*

* For searches and help try:

* http://www.stata.com/support/faqs/res/findit.html

* http://www.stata.com/support/statalist/faq

* http://www.ats.ucla.edu/stat/stata/

**References**:**st: how to create case id number***From:*"Seok-Woo Kwon" <swkwon@uky.edu>

**Re: st: how to create case id number***From:*"Eric G. Wruck" <ewruck@econalytics.com>

- Prev by Date:
**st: Version control questions** - Next by Date:
**st: RE: Version control questions** - Previous by thread:
**Re: st: how to create case id number** - Next by thread:
**RE: st: how to create case id number** - Index(es):

© Copyright 1996–2017 StataCorp LLC | Terms of use | Privacy | Contact us | What's new | Site index |