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 on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: the use of loop


From   shihying yao <berkeley.yao@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: the use of loop
Date   Wed, 11 Apr 2012 16:48:20 -0400

Dear all,
I have a question regarding the use of loop in Stata 10, and would
appreciate any help.

The data is composed of item scores from two graders. Each variable
represents a combination of a grader and an item. For example, the
variable "Item1aEB" represents scores of Item 1a by grader EB, and
"Item1aAD" represents Item 1a scores by grader AD. The goal is to
compare consistency in ratings (e.g., compare values of "Item1aEB" and
"Item1aAD").

The problem I have now is how to do this comparison efficiently over
all items using a loop. For example, suppose I want to calculate the
difference in ratings (e.g. gen Item1a=Item1aEB - Item1aAD) repeatedly
for Items 1a,1b,and 1c. I tried "foreach" command

foreach x of varlist Item1aEB- Item1cAD{
gen `x'= `x'EB - `x'AD
}

This syntax is wrong because Stata will think variables are named as,
say "Item1aEBEB", rather than "Item1aEB." But I am not sure how to
correct this command. Any advice is appreciated!
*
*   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