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]
st: foreach loop for scoring answers
From
Brandon Olszewski <[email protected]>
To
[email protected]
Subject
st: foreach loop for scoring answers
Date
Mon, 21 Jun 2010 16:51:15 -0700
I have a data set containing answers from 100 student answers to a
50-item test; one of the "students" is the answer key (id=101). I want
to create new variables coded 0/1 (incorrect/correct) by comparing
student answers to the key's answers. I realize I could do this
somewhat barbarically, like this:
gen correct_1=<manually enter correct answer for question 1>
gen dummy_1=0
replace dummy_1=1 if answer_1==correct_1
...and so on, copying syntax and replacing '1' with whatever number
question I'm working with.
Instead, I want to do this more elegantly by writing a macro that will
do this for me. I understand that I can use the foreach or forvalues
commands to accomplish this, but am lost on how to get started with
them, as my unix language skills and familiarity with macros are not
up to par. I'm also unsure about how to use one of my cases (the key,
id=101) in the comparative way I've described (to create values for
in/correct answers from the 100 other cases). I have checked previous
do-files (that colleagues have built with me) and stata documentation
but am unable to make solid sense out of them for my purposes.
Any help is appreciated.
Best,
Brandon Olszewski
*
* 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/