Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[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 <mwhite@poverty-action.org>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Checking if one variable = any of the values of another
Date   Thu, 8 Dec 2011 01:13:44 -0500

Premature send. Let's try this again:

***BEGIN***
encode from_user, generate(encuser) label(user)
summarize encuser, meanonly
local max = r(max)
drop encuser

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

Best,
Matt

On Thu, Dec 8, 2011 at 1:09 AM, Matthew White <mwhite@poverty-action.org> wrote:
> 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
> <maria.davydenko@gmail.com> 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



-- 
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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index