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

st: Re: working within bygroups


From   Christopher F Baum <[email protected]>
To   [email protected]
Subject   st: Re: working within bygroups
Date   Sat, 8 May 2004 07:25:51 -0400

To indicate whether a borrower's issues in a particular market are seasoned, Nick wrote

bysort borrower mkttype (issuedate) : gen newmkttype = _n > 1

On May 8, 2004, at 2:33 AM, Adrian wrote:


Nick, thank you very much. I was not familiar with this structure of
generating variables by assigning them a value and adding extra
conditions, like this:

_n > 1

I think I still need time to digest this as I don't understand very well
the structure behind this command. It has certainly been very useful,
though. Thank you.
Note that Nick's command

gen newmkttype = _n>1

is not "assigning a value and adding extra conditions": it is defining a Boolean
condition, evaluating to (0,1). Let us say that within a by-group (simple structure: issuer issue_date)
we want to flag those issues which are the third issues by that issuer. Then

bysort issuer (isser_date) : gen thirdiss = _n==3

would do that. It is just a matter of setting a logical condition on the RHS which expresses
what you would like to pick off. The above can be written in terms of instructions to a RA:

For each one of the issuers,
Sort the issues by issue_date
Put a flag on the third issue of that issuer

and Adrian's original problem is just a variation on that theme (with one more by-variable: the market type).

Kit

*
* 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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index