Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down at the end of May, and its replacement, **statalist.org** is already up and running.

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

From |
"Martin Weiss" <martin.weiss1@gmx.de> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: RE: Comparing variables by observation |

Date |
Tue, 21 Sep 2010 21:16:59 +0200 |

<> No need for the "[_n]", as Stata compares row by row anyway. " gen (1) =" will lead to "invalid name" complaints. Use a better varname... The -cond()- does not seem to do anything for you there, but then again, we talked about it in another recent thread... HTH Martin -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Anisa Shyti Sent: Dienstag, 21. September 2010 21:13 To: statalist@hsphsun2.harvard.edu Subject: Re: st: RE: Comparing variables by observation I tried the following codes: by obscode, sort: gen (1) = cond(5>= X1 & X1>= X2 & X2>=X3 & X3>=4, 1, 0) by obscode, sort: gen (2) = cond(X1<=3 & 5<= X3, 1, 0) I also tried: gen byte cond2 = X5t[_n] <=3 & X7t[_n] >=5 Is this approach correct? I will try what you both suggest. Otherwise, I'll have to look for a logical problem.. Thank you very much. anisa On Tue, Sep 21, 2010 at 8:57 PM, Nick Cox <n.j.cox@durham.ac.uk> wrote: > No code of yours allows no comment on that. > > Responding to the algebra given, this kind of problem is one in which Stata's syntax is inescapably long-winded. To save checking on precedence rules I tend to parenthesise aggressively: > > (5 >= X1) & (X1 >= X2) & (X2 >= X3) & (X3 >= 4) > > (X1 <= 3) & (5 <= X3) > > What you wrote is not illegal but it will be interpreted in terms of 1s and 0s as explained at length in > > http://www.stata.com/support/faqs/data/trueorfalse.html > > which will usually yield something quite different from what you want. > > Nick > n.j.cox@durham.ac.uk > > Anisa Shyti > > I have three variables X1 X2 X3 > (taking values from 1 to 10) and I need to compare their values, by > observation, according to several conditions (which are theoretically > derived) of the form, examples: (1) 5>= X1 >=X2 >=X3 >=4; (2) X1<=3 > and 5<= X3. I need to evaluate each condition on the data by counting > the number of times it is met, in order to classify the observations. > > I tried several approaches, but the total number of classified > observations exceeds the total number of observations. So, I am > guessing I have some redundant counts - maybe I am doing something > wrong with the coding (given that the conditions are correct). > > > * > * 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/ > * * 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/ * * 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/

**References**:**st: Comparing variables by observation***From:*Anisa Shyti <anisa.shyti@gmail.com>

**st: RE: Comparing variables by observation***From:*Nick Cox <n.j.cox@durham.ac.uk>

**Re: st: RE: Comparing variables by observation***From:*Anisa Shyti <anisa.shyti@gmail.com>

- Prev by Date:
**RE: st: RE: Comparing variables by observation** - Next by Date:
**Re: st: RE: Comparing variables by observation** - Previous by thread:
**RE: st: RE: Comparing variables by observation** - Next by thread:
**st: RE: Comparing variables by observation** - Index(es):