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

st: RE: Populating a new variable based on comparisons between observations

From   "Nick Cox" <>
To   <>
Subject   st: RE: Populating a new variable based on comparisons between observations
Date   Wed, 18 Mar 2009 19:32:20 -0000

Several recent threads over the last few days have focused on
essentially the same issue. See the threads started by Eunsu Ju and
Alexander Severinsen, for example. 

There's a one-word answer: -by:-. 

This one sounds like 

bysort Company_GVKEY (Deal_Date) : gen Latest_Company_Name =



I need to do comparisons between observations, and create a new variable
based on this comparison. Here is the situation. I have data on
alliances between companies for the years 1962 to 2009. One aspect of
this data is that sometimes the company name changes over time, but the
permanent identifier (GVKEY) remains the same, and I need to find a way
to identify the latest company name. The data looks like this

Deal_Number, Deal_Date, Company_Name, Company_GVKEY. 
1, 2006, Apple computer, APP
2, 2009, Apple Inc, APP
2, 2009, Microsoft, MS

Here, company_name has changed over time from "apple computer" to "apple
inc" but the GVKEY remains the same (APP).  I want to create a new
variable called "Latest_Company_Name" which is populated by the name in
the observation which has the later Deal_Date.  

So I want the data to look like this:

Deal_Number; Deal_Date; Company_Name; Company_GVKEY;
1, 2006; Apple computer; APP; Apple Inc
2, 2009; Apple Inc; APP; Apple Inc
3, 2009, Microsoft, MS, Microsoft

I will really appreciate any suggestions as to how to do the above. 

Thanks so much. I also would like to especially appreciate and thank
this list for responses to previous questions. I don't think I could
have made the progress I have on my research without this list.  A big
thank you to the people who have taken the time to respond. I'm humbled
by your generosity.    

*   For searches and help try:

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