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: Re: Group classification


From   "Joseph Coveney" <[email protected]>
To   <[email protected]>
Subject   st: Re: Group classification
Date   Sun, 14 Jul 2013 21:27:36 +0900

Mario Jose wrote:

I have a dataset with foreign subsidiaries over a period of time. Each
subsidiary is owned by an identified parent company. For each year,
there are parent companies with subs in a set of countries y1,.., yn
and parents with subs in a different set of companies x1, ..., xm.
There are also parent companies with subs in both set of countries. I
would like to allocate 0,1 to observations according to whether or not
the respective parent has subs in the countries x1,..., xm. For
instance, if a parent company has subs in y1, y2, y6 I want to
allocate 1 to all these observations, if another parent company has
subs in countries y1, y2 and x5 I want to allocate 0 to all subs of
that parent (because the parent has a subs in country x5).

Any suggestion on how to do this?
I will be grateful for any help.



If I understand what you're trying to do, then it would be something like
generating an indicator variable based either upon an -inlist()- or a -foreach-
loop, and then using -bysort . . . egen-.  You'd use -inlist()- if the list of
countries is short enough, and a -foreach- loop otherwise.  Something like that
below might be able to give you an idea where to start.

Joseph Coveney

. input str1 parent str2 subsidiary str2 country

        parent  subsidi~y    country
  1. A AA y1
  2. A AB y2
  3. A AC y6
  4. B BA y1
  5. B BB y2
  6. B BC x5
  7. end

. 
. generate byte in_an_x = 0

. foreach country in "x1" "x2" "x3" "x4" "x5" "x6" "xm" {
  2.         quietly replace in_an_x = 1 if country == "`country'"
  3. }

. bysort parent (subsidiary):  egen byte allocate = max(in_an_x)

. quietly replace allocate = !allocate

. 
. list, noobs sepby(parent) abbreviate(20)

  +----------------------------------------------------+
  | parent   subsidiary   country   in_an_x   allocate |
  |----------------------------------------------------|
  |      A           AA        y1         0          1 |
  |      A           AB        y2         0          1 |
  |      A           AC        y6         0          1 |
  |----------------------------------------------------|
  |      B           BA        y1         0          0 |
  |      B           BB        y2         0          0 |
  |      B           BC        x5         1          0 |
  +----------------------------------------------------+

. 
. exit

end of do-file


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