Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: panel data dummy creation/incorporation


From   Andrew Reed <[email protected]>
To   [email protected]
Subject   st: panel data dummy creation/incorporation
Date   Mon, 19 Aug 2013 12:39:03 +0200

I have been struggling with this for a few days and the closest I've come to finding a decent answer is by way of the collapse command.

I have 79 different entities in a panel data set, where each entity has its own specific set of information concerning. The dummy variable takes on a value of 1 if there has occurred an event (credit rating movement) for that particular id/entity. 

What I want to do from this point is to create, for each entity again, a new dummy variable where the value of 1 signifies an event occurring to every entity but the entity itself that i am creating the dummy for. As mentioned before, the collapse command gives me the exact output i'd like, collapsing the dummy variable by date across all id's. This also gives me the option to exclude the id value I am creating the dummy for. The code is as follows.

collapse (max) event_variable if id!=(id value), by date

The major problem is that I have to copy/paste this input back into the dataset and go through each id value individually.

I'm therefore trying to incorporate a foreach statement in order to have this same type of operation go through the data set and automatically create the measure I want for each id value.  I'm still a bit confused as all of the reading i've seen is using the summation function and not quite the collapse function that has worked to give me exactly what I wanted, just in a not-so-elegant way.

I would gladly accept generating a new variable where, for each id value, the dummy values for all other id values are added, and from this point i could just replace all values that are not 0 with 1. I have included a visual representation of what I want to do below, where newevent is the new dummy.

id              event      time      newevent
1                  0             1                1
1                  1             2                0
1                  0             3                1
1                  0             4                0
1                  0             5                1
2                  1             1                0
2                  0             2                1
2                  1             3                0
2                  0             4                0
2                  0             5                1
3                  0             1                1
3                  0             2                1
3                  0             3                1
3                  0             4                0
3                  1             5                0

I hope this makes sense and someone may have something using 'foreach' or 'by id, sort' that can help me in doing this.

Thanks

Andrew Reed


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index