# Re: st: flagging a specific pattern of values within observations

 From "Jeremy Miles" To statalist@hsphsun2.harvard.edu Subject Re: st: flagging a specific pattern of values within observations Date Tue, 24 Apr 2007 10:26:56 -0700

Assuming that you don't want to do it manually:

- gen flag = 1 if q11a == q11b | q11a == q11c ... -

Here are a couple of options.

You know that the sum should be 6 (or k(k+1)/2 ), so you could check the sum.

You also know that the product should be some number (I can't work it out).

These would both detect one error, but would not detect two errors.

A method that sometimes works is to assign a prime number to each value.
1 = 2
2 = 3
3 = 5
4 = 7
5 = 11

Then calculate the product.  There is only one unique combination of
numbers that will give the correct product.  The products can get very
large, very quickly though.

Another approach, which will take a bit more coding, would be to
reshape the data, to make it short and wide.  You can then

fid     q11a    q11b    q11c
55      2               3       1
21      1               2       1

fid 55 21
q11a 2 1
q11b 3 2
q11c 1 1

Then keep only the one variable, sort it, and check that there is an
ascending order.

There are probably other solutions I haven't though of.  :)

Jeremy

On 24/04/07, Anirudh V. S. Ruhil <ruhil@ohio.edu> wrote:
A colleague is trying to accomplish something in a different stats package
and asked if STATA could effect the solution. "Of course", said I. Now I am
scratching my head for the code.  Individuals were asked to rank-order 3
choices. Person 55 did fine, but not Person 21. How can I generate a flag
for such respondent-errors?

----------------------------
fid     q11a    q11b    q11c
55      2               3       1
21      1               2       1
----------------------------

Ani

*
*   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/

--
Jeremy Miles
Learning statistics blog: www.jeremymiles.co.uk/learningstats
Psychology Research Methods Wiki: www.researchmethodsinpsychology.com
*
*   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/