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: Question About Evaluating Expressions


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Question About Evaluating Expressions
Date   Thu, 18 Apr 2013 15:11:48 +0100

Corrected below.

Nick
[email protected]


On 18 April 2013 15:09, Nick Cox <[email protected]> wrote:
> generate bin_number = ""
> local u 10
>
> forvalues i = 900(`u')1500 {
>      local I = `i' + `u'
>     replace bin_number = "`i'-`I'" if  condition > `i' & condition <= `I'
> }
>
> It could be done with one fewer line, the price being a veritable
> snowstorm of quotation marks:
>
> generate bin_number = ""
> local u 10
>
> forvalues i = 900(`u')1500 {
>      replace bin_number = "`i'-`=`i' + `u''" if (condition > `i' &
> condition <= `i' + `u')
> }
>
> Nick
> [email protected]
>
>
> On 18 April 2013 15:03, Erika Kociolek <[email protected]> wrote:
>> I am trying to "bin" some data into categories using the code below. I
>> would like the bin_number variable to look like this:
>>
>> condition     bin_number
>> 905             900-910
>>
>> If I run the code below, using condition = 905 as an example, I get
>> the following:
>> condition     bin_number
>> 905             900-(900+10)
>>
>> How do I get Stata to first evaluate what's in the parentheses and
>> then put the result into the bin_number variable?
>>
>> Code:
>> generate bin_number = ""
>> local u 10
>>
>> forvalues i = 900(`u')1500{
>>      replace bin_number = "`i'" + "-" + "(`i' + `u')" if (condition >
>> `i' & condition <= `i' + `u')
>> }
>>
>> Any advice would be greatly appreciated.
>> Erika
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index