Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: Creating a dummy variable under certain conditions


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Creating a dummy variable under certain conditions
Date   Sat, 2 Jun 2012 15:29:42 +0100

You will probably want to exclude or ignore the first few observations
in each panel or -replace- it with missing. Otherwise, what's wrong?

Abhimanyu's slip has already been corrected in this thread, as below.

Nick

On Sat, Jun 2, 2012 at 3:12 PM, sebas nicaise <sebasnicaise@hotmail.com> wrote:

> Thank you for the quick replys.
>
>  However, the suggested solutions did not give the right answer.
>
> Nick, your solution gives me way too many 1's. I do think the first step with the cusum was the right way to go.
>
>  Abhimanyu, your solution does not distinquish between the id's, the calculation has to start over for every gvkey.
>
>
>  Hope you can have another look at it, I will also try to work with the suggestions you gave me.
>
>> From: abhimanyu.arora1987@gmail.com
>> To: statalist@hsphsun2.harvard.edu
>>
>> Thanks Nick, yes.
>> But I would go for your solution which would be better in case he had
>> a longer lag.
>>
>> On Sat, Jun 2, 2012 at 2:56 PM, Nick Cox <njcoxstata@gmail.com> wrote:
>> > This looks OK as long as you substitute -viol- for -gvkey-. The
>> > previous values concerned are for -viol-, not -gvkey-.
>> >
>> > Nick
>> >
>> > On Sat, Jun 2, 2012 at 1:51 PM, Abhimanyu Arora
>> > <abhimanyu.arora1987@gmail.com> wrote:
>> >
>> >> Try this if your data is -xtset-ted
>> >> gen new_viol_dummy=L.gvkey+L2.gvkey+L3.gvkey+L4.gvkey==0
>> >
>> >> On Sat, Jun 2, 2012 at 2:06 PM, sebas nicaise <sebasnicaise@hotmail.com>
>> >>
>> >>> I am struggeling with creating a new dummy variable. I have a very large
>> >>> (unbalanced) panel dataset that looks like this:
>> >>>
>> >>>
>> >>>
>> >>> date gvkey viol
>> >>> 1997q1 1021 0
>> >>> 1997q2 1021 0
>> >>> 1997q3 1021 0
>> >>> 1997q4 1021 0
>> >>> 1998q1 1021 1
>> >>> 1998q2 1021 0
>> >>> 1998q3 1021 0
>> >>> 1998q4 1021 1
>> >>> 1999q1 1021 0
>> >>>
>> >>> 1999q2 1021 0
>> >>>
>> >>> 1999q3 1021 0
>> >>> 1999q2 1023 0
>> >>> 1999q3 1023 1
>> >>> 1999q4 1023 0
>> >>> 2000q1 1023 0
>> >>> 2000q2 1023 1
>> >>>
>> >>>
>> >>> Where date is calender quarter, gvkey is the company identifier and viol a
>> >>> dummy which equals 1 if the firm is in violation of a covenant in a private
>> >>> debt contract.
>> >>>
>> >>>
>> >>>
>> >>> The problem is that I have to create a new dummy variable ( new violation)
>> >>> which meets certain conditions.
>> >>>
>> >>> The new violation dummy is only allowed to be 1 if in the previous 4
>> >>> quarters of a certain company (gvkey) is 0.
>> >>>
>> >>>
>> >>>
>> >>> This means for example that:
>> >>>
>> >>>
>> >>>
>> >>> date gvkey viol Newviolation
>> >>> 1997q1 1021 0 0
>> >>> 1997q2 1021 0 0
>> >>> 1997q3 1021 0 0
>> >>> 1997q4 1021 0 0
>> >>> 1998q1 1021 1 1
>> >>> 1998q2 1021 0 0
>> >>> 1998q3 1021 0 0
>> >>> 1998q4 1021 1 0
>> >>> 1999q1 1021 0 0
>> >>>
>> >>> 1999q2 1021 0 0
>> >>>
>> >>> 1999q3 1021 0 0
>> >>> 1999q2 1023 0 0
>> >>> 1999q3 1023 1 0
>> >>> 1999q4 1023 0 0
>> >>> 2000q1 1023 0 0
>> >>> 2000q2 1023 1 0
>> >>>
>> >>>
>> >>>
>> >>> I do not know how to tell Stata to create this variable, Hope someone is
>> >>> so kind to help me.
>> >
>> > *
>> > * 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/

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index