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   Scott Merryman <[email protected]>
To   [email protected]
Subject   Re: st: identifyng records in a group that have a field with nearby values from another group
Date   Thu, 8 Oct 2009 07:22:44 -0500

On Wed, Oct 7, 2009 at 3:49 PM, Michael McCulloch <[email protected]> wrote:
> 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
>

No - there is nothing specific to Stata 11.   Perhaps -set trace on-
will point out the problem.

Below is the output from the example:


. sysuse auto, clear
(1978 Automobile Data)

. levelsof price if fore ==1 ,local(levels)
3748 3798 3895 3995 4296 4499 4589 4697 5079 5397 5719 5799 5899 6229
6295 6850 7140 8129 9690 9735 11995 12990

. foreach l of local levels {
  2.     qui gen group_`l' = 1 if price  >  `l' -200 &  price  < `l' +
200 & fore == 0
  3. }

. sort price

. l fore make price if group_4296 ==1

     +----------------------------------+
     |  foreign   make            price |
     |----------------------------------|
 15. | Domestic   AMC Concord     4,099 |
 16. | Domestic   Pont. Sunbird   4,172 |
 17. | Domestic   Olds Omega      4,181 |
 18. | Domestic   Ford Mustang    4,187 |
 19. | Domestic   Olds Starfire   4,195 |
     |----------------------------------|
 21. | Domestic   Ford Fiesta     4,389 |
 22. | Domestic   Pont. Phoenix   4,424 |
 23. | Domestic   Plym. Champ     4,425 |
 24. | Domestic   Buick Opel      4,453 |
 25. | Domestic   Plym. Horizon   4,482 |
     +----------------------------------+

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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index