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: st: Re: st: generating variables for group members conditional on member's own values and values for other group members‏


From   Eric Booth <[email protected]>
To   <[email protected]>
Subject   st: Re: st: Re: st: generating variables for group members conditional on member's own values and values for other group members‏
Date   Mon, 10 Jan 2011 10:07:50 -0600

<>

I think this is what you are asking for:

***added to end of prev example-->
bys project_id: egen x2_new = max(x2)
replace x2_new = . if x2==org_new
***

The distinction of orgs i & j for questions like these becomes muddled because as you loop over the observations, every org is at some point i or j within each project_id.  During your analysis, you may find it useful to, at some points, reshape your data to wide to help work across orgs in a project.


- Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]


On Jan 10, 2011, at 3:47 AM, <[email protected]>
 <[email protected]> wrote:

> Dear Eric and statalist.
> 
> Thank you for helping me along.
> When I run the suggested code it generates the desired values for org_id (j) rather than for org_id (i). 
> 
> Is there a way to generate the desired values for org_id (i)?
> 
> Sincerely,
> 
> Erik Aadland.
> 
> 
> <>
> 
> Assuming there are no cases in your full dataset where there are more
> than one case in each project with a new niche value==1 & 
> has nonmissing org_elite value) :
> 
> ***********************!
> /* setup */
> clear
> inp project_id  org_id  org_elite  org_new  new_niche
> 1   1   1  0.9    0 
> 1   2   0.9  0.2    1
> 1   3   0.1  0.3    0
> 1   6   0  0   0
> 2   4   0.5  0.86   1
> 2   5   .  .   0 
> 2   1   1  0.9    0 
> 3   6   0.5  0.9    1
> 3   7   .  0.9    0
> end
> 
> /*   QUESTION 1
> I am trying to generate a variable X by project_id 
> and org_id that does the following:
> if org_id (i) has an org_elite value that is ( > 0 <.)
> and collaborates with another org_id (j) 
> with an org_new value (> 0.85) and that org_id (j)
> has a new niche value =1, then org_id (i) gets a 
> value of 1 and 0 otherwise on the new variable X.
> */
> 
> 
> bys project_id: egen m_org_new = max(org_new)  ///
>    if new_niche==1
> g x = 1 if m_org_new > .85  &   ///
>    org_elite>0 & !mi(org_elite, m_org_new)
> recode x (.=0)
> 
> 
> 
> /*   QUESTION 2
> Similarly, I am trying to generate a variable X2 by 
> project_id and org_id that does the following:
> if org_id (i) has a new niche value =1, and collaborates
> with another org_id (j) that has an org_elite value ( <.),
> then org_id (i) gets a value on the new variable X2 that 
> equals the org_elite value for org_id (j).
> */
> 
> g x2 =  m_org_new if !mi(m_org_new, org_elite) 
> 
> ************************!
> 
> - Eric
> 
> __
> Eric A. Booth
> Public Policy Research Institute
> Texas A&M University
> [email protected]
> Office: +979.845.6754
> Fax: +979.845.0249
> http://ppri.tamu.edu
> 
> 
> On Jan 9, 2011, at 11:36 AM, <[email protected]>
> wrote:
> 
>> project_id     org_id             org_elite     org_new     new_niche
>> 1                      1               1        0.9                0 
>> 1                      2               0.9      0.2                1
>> 1                      3               0.1      0.3                0
>> 1                      6               0        0                  0
>> 2                      4               0.5      0.86               1
>> 2                      5               .        .                  0 
>> 2                      1               1        0.9                0 
>> 3                      6               0.5      0.9                1
>> 3                      7               .        0.9                0
>> 
>> I am trying to generate a variable X by project_id and org_id that does the following:
>> 
>> if org_id (i) has an org_elite value that is ( > 0 <.) , and collaborates with another org_id (j) with an org_new value (> 0.85) and that org_id (j) has a new niche value =1, then org_id (i) gets a value of 1 and 0 otherwise on the new variable X.
>> 
>> Similarly, I am trying to generate a variable X2 by project_id and org_id that does the following:
>> 
>> if org_id (i) has a new niche value =1, and collaborates with another org_id (j) that has an org_elite value ( <.), then org_id (i) gets a value on the new variable X2 that equals the org_elite value for org_id (j).
> 
> 
> 
> *
> *   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index