Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: Sorting Data (2)


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: Sorting Data (2)
Date   Wed, 13 Nov 2002 17:48:54 -0000

Here's another way (better) to do it:

. l Country vote?

       Country      vote1      vote2      vote3      vote4      vote5
  1.   Albania          N          Y          N          N          Y
  2.   Algeria          N          Y          Y          A          Y
  3. Argentina          Y          N          Y          Y          Y
  4.       USA          Y          N          Y          Y          A

Initialise a counter:

. gen agreesUS = 0

We note empirically that USA is observation 4.

. forval i = 1/5 {
	replace agreesUS = agreesUS + (vote`i' == vote`i'[4])
}

. l Country vote? agrees

       Country      vote1      vote2      vote3      vote4      vote5
agreesUS
  1.   Albania          N          Y          N          N          Y
0
  2.   Algeria          N          Y          Y          A          Y
1
  3. Argentina          Y          N          Y          Y          Y
4
  4.       USA          Y          N          Y          Y          A
5

Nick
n.j.cox@durham.ac.uk

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



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