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]

Re: st: Checking if one variable = any of the values of another


From   Matthew White <[email protected]>
To   [email protected]
Subject   Re: st: Checking if one variable = any of the values of another
Date   Thu, 8 Dec 2011 01:09:54 -0500

Hi Maria,

This might be one way to do it:
***BEGIN***
encode from_user, generate(encuser) label(user)
summarize encuser
local max = r(max)
drop encuser

gen grpment = 0
forvalues i = 1/11 {
	encode m1, generate(encm) label(user)
	replace grpment = 1 if enc <= `max'
	drop encm
}
***END***

Best,
Matt

On Wed, Dec 7, 2011 at 7:17 PM, Maria Davydenko
<[email protected]> wrote:
> Hey all,
>
> I have a Twitter data set where each observation includes the user who
> tweeted (var from_user), what they tweeted (var text) as well as
> variables m1 through m11 (up to 11 users they mentioned in var text).
> I want to create an indicator variable grpment that =1 if any of the m
> (match) variables for a given observation are equal to any of the
> other values of from_user.  Here's what it looks like:
>
> from_user       text            m1      m2 …11  grpment
> P1              @P2             P2                      1
> P2              @other                                  0
> P3              @P1 @P2 P1      P2              1
>
> In human speak, I want to see if the from_user is mentioning any of
> the other from_users, based on the 11 different m variables.
>
> I have it all figured out except the grpment element.  So far, I've
> been playing with loops but can't think of anything short of a giant
> macro that could make this work. If you have any insight, it would be
> much appreciated!
>
> Thanks,
>
> Maria
>
> *
> *   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/



-- 
Matthew White
Data Coordinator
Innovations for Poverty Action
101 Whitney Avenue, New Haven, CT 06510 USA
+1 434-305-9861
www.poverty-action.org

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