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: foreach loop for scoring answers


From   Brandon Olszewski <olszewski.brandon@gmail.com>
To   statalist@hsphsun2.harvard.edu
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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index