Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: More than 2 arguments for by


From   "Ashim Kapoor" <[email protected]>
To   [email protected]
Subject   Re: st: RE: More than 2 arguments for by
Date   Tue, 16 Sep 2008 20:50:43 +0530

Hello Nick,

I made a "silly" mistake. I realized it only some time ago.

What I wanted to do was : -

sort year state cnum votes

and then ONLY do

by year state cnum : keep if _n==_N

This would bring out the item with the max no of votes in a year in a
state in a contituency.

I erred and thought that I should do by year state cnum VOTE : keep if _n==_N.

Regards,
Ashim.

On Tue, Sep 16, 2008 at 8:09 PM, Nick Cox <[email protected]> wrote:
> Neil Shephard and Martin Weiss made helpful comments.
>
> My guess is that what Ashim needs is
>
> bysort year state cnum (votes) : keep if _n == _N
>
> except that his report "I have ." leads me to guess that he has missing
> values, which would be problematic with that code.
>
> Missing values are sorted to the end of any block of observations, as
> they are treated as arbitrarily large. So missing values will show up in
> the kept data for every constituency (if that is what -cnum- indexes)
> for which they exist.
>
> Even if this guess is correct, it raises two questions.
>
> 1. Why does Ashim have missings? Are they something else, e.g. zeros? If
> so, they should be fixed.
>
> 2. If the missings are genuine, they need to be fixed before -sort-ing.
> Ashim's purpose seems to call for
>
> drop if missing(votes)
>
> Also -search dropmiss-.
>
> Nick
> [email protected]
>
> Ashim Kapoor
>
> I want to do the following :
>
> sort year state cnum votes
>
> by year stata cnum votes : keep if _n==_N
>
> That way I get the guy with the max no of votes.
>
> Now when I do this for 1 or 2 arguments for by then it works, but not
> for 4 arguments I have . Does by have a limit on how many arguments it
> can have ?
>
> I read -help by- and that does mention using by in the following
> fashion : -- > by year ( state) . Do I need to put in brackets for the
> other arguments?
>
> Could someone please clarify?
>
> *
> *   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/



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