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

st: RE: Check existence within a group


From   "de la Garza, Adrian" <[email protected]>
To   <[email protected]>
Subject   st: RE: Check existence within a group
Date   Fri, 7 May 2004 11:24:53 -0400

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.

And just a comment about the way I want to construct this dummy (I guess
you would code 1 for new and 0 for old), think of it as if the dummy
signaled when the borrower has already "experience" in a particular
market type. This construction is better for our own regression
interpretation purposes.

Thanks again.
Adrian


> -----Original Message-----
> From: Nick Cox [mailto:[email protected]] 
> Sent: Friday, May 07, 2004 10:54 AM
> To: [email protected]
> Subject: st: Check existence within a group
> 
> 
> Your guess is right. You don't need a loop at all. 
> Stata is very good at doing this kind of thing 
> without loops. 
> 
> Your variable -newmkttype- is coded 0 for new, 1 for old. 
> Not the way that I would do it, but that's not important. 
> 
> You can get it from 
> 
> bysort borrower mkttype (issuedate) : gen newmkttype = _n > 1 
> 
> That is we sort first on -borrower-, within -borrower- on 
> -mkttype-, and within -mkttype- on -issuedate-. Then you want 
> the first occurrence within blocks of -borrower mkttype- 
> to be flagged as new, by coding as 0, and later occurrences as
> not new, and so coded 1. This is achieved by 
> 
> _n > 1 
> 
> which evaluates as 0 if _n == 1 and 1 otherwise. 
> 
> de la Garza, Adrian
>  
> > I have a database that contains info on bonds issued as follows:
> > 
> > borrower	issuedate	mtydate	amount	mkttype
> > ABN Amro	04Jun93	03Jun98	50		E
> > ABN Amro	19Sep94	17Jul96	100		E
> > ABN Amro	22Nov94	21Nov98	50		S
> > ...
> > ACINDAR	02Feb92	30Jan99	200		L
> > ACINDAR	20Mar92	19Mar97	50		E
> > ACINDAR	29Jul94	28Mar00	175		L
> > ...
> > 
> > and I want to create a variable -newmkttype- that tells me if the
> > borrower is issuing a bond in a completely new and unknown 
> > market type.
> > If it is, then I want this variable to take the value of 0. 
> If, on the
> > contrary, the borrower has issued bonds in this market type 
> > in the past,
> > then I want this variable to take the value of 1 (notice that the
> > database is sorted by borrower issuedate mtydate amount).
> > 
> > borrower	issuedate	mtydate	amount	mkttype	newmkttype
> > ABN Amro	04Jun93	03Jun98	50		E		0
> > ABN Amro	19Sep94	17Jul96	100		E		1
> > ABN Amro	22Nov94	21Nov98	50		S		0
> > ...
> > ACINDAR	02Feb92	30Jan99	200		L		0
> > ACINDAR	20Mar92	19Mar97	50		E		0
> > ACINDAR	29Jul94	28Mar00	175		L		1
> > ...
> > 
> > How can I construct this variable? Is there an easy way of 
> > checking the
> > borrower's history to determine whether -newmkttype- should 
> > get a 0 or a
> > 1, without writing a complicated loop?
> 
> *
> *   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/
> 

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