Statalist


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

Re: st: identifyng records in a group that have a field with nearby values from another group


From   Michael McCulloch <[email protected]>
To   [email protected]
Subject   Re: st: identifyng records in a group that have a field with nearby values from another group
Date   Wed, 7 Oct 2009 13:49:30 -0700

Thanks Scott. Is the code in the second line of the loop, beginning  
with -gen- specific to Stata11?
At that line my Stata10 returns "unrecognized command:      generate  
invalid command name"
Michael

sysuse auto, clear
levelsof price if fore ==1 ,local(levels)
foreach l of local levels {
     gen group_`l' = 1 if price  >  `l' -200 &  price  < `l' + 200 &  
fore == 0
}
sort price
l fore make price if group_4296 ==1



On Oct 7, 2009, at 1:01 PM, Scott Merryman wrote:

> On Wed, Oct 7, 2009 at 2:33 PM, Michael McCulloch
> <[email protected]> wrote:
>> Hello,
>> I have a dataset with two groups, for example "foreign" and  
>> "domestic" in
>> the auto dataset.
>> For example:
>>        sysuse auto, clear
>>        sort foreign price
>>        list foreign make price
>>
>> My question is, how to identify "domestic" cars that are within  
>> $200 in
>> price from each "foreign" car, and create another variable called  
>> "group"
>> that mark these sets?
>>
>> In this case, that would be:
>>        Foreign   Fiat Strada           4,296
>>        Domestic        AMC Concord                     4,099
>>        Domestic        Pont. Sunbird                   4,172
>>        Domestic        Olds Omega                      4,181
>>        Domestic        Ford Mustang                    4,187
>>        Domestic        Olds Starfire                   4,195
>>        Domestic        Ford Fiesta                     4,389
>>        Domestic        Pont. Phoenix                   4,424
>>        Domestic        Plym. Champ                     4,425
>>        Domestic        Buick Opel                      4,453
>>        Domestic        Plym. Horizon                   4,482
>>
>
> Something like this?
>
> sysuse auto, clear
> levelsof price if fore ==1 ,local(levels)
> foreach l of local levels {
>     gen group_`l' = 1 if price  >  `l' -200 &  price  < `l' + 200 &  
> fore == 0
> }
> sort price
> l fore make price if group_4296 ==1
>
> Scott
>
> *
> *   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/



Michael McCulloch, LAc MPH PhD
Pine Street Foundation
124 Pine Street
San Anselmo, CA 94960-2674
tel:	415-407-1357
fax: 	206-338-2391
[email protected]







*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index