Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

st: the use of loop

From   shihying yao <>
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

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:

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