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: The accuracy of the float data type
From
Nick Cox <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: The accuracy of the float data type
Date
Fri, 24 Jan 2014 16:33:06 +0000
Nevertheless Rochelle's question remains. Both variables are -float-.
The display format is not pertinent. This test does not reproduce
Rochelle's problem.
. clear
. input firmID segmentID sales year
firmID segmentID sales year
1. 1001 1 25.395 1990
2. 1001 1 32.007 1991
3. end
. egen maxsales = max(sales), by(firmID year)
. l if sales == maxsales
+----------------------------------------------+
| firmID segmen~D sales year maxsales |
|----------------------------------------------|
1. | 1001 1 25.395 1990 25.395 |
2. | 1001 1 32.007 1991 32.007 |
+----------------------------------------------+
Note as above that the double equals sign == is needed here.
Nick
[email protected]
On 24 January 2014 16:23, Maarten Buis <[email protected]> wrote:
> I would do this differently:
>
> *------------------ begin example ------------------
> // get some example data
> sysuse auto
>
> // create a variable denoting missing values
> gen byte miss = missing(rep78, price)
>
> // create our indicator variable
> bys rep78 miss (price) : gen max = _n == _N if !miss
>
> // admire the result
> list rep78 miss price max in 1/12, sepby(rep78)
> *------------------- end example -------------------
> * (For more on examples I sent to the Statalist see:
> * http://www.maartenbuis.nl/example_faq )
>
> Hope this helps,
> Maarten
>
>
> On Fri, Jan 24, 2014 at 4:53 PM, R Zhang <[email protected]> wrote:
>> Dear Statalist,
>>
>> my data structure is as follows
>>
>> firmID segmentID sales year
>> 1001 1 25.395 1990
>> 1001 1 32.007 1991
>>
>> ............
>>
>> a firm can operate in multiple segments as identified by segmentID .
>> I wanted to identify the largest segment by sales,so I used
>>
>> bysort firmID year : egen maxsale=max(sales)
>>
>> then I did
>> gen PriSIC=0
>> replace PriSIC=1 if sales=maxsale
>>
>> I got
>> firmID segmentID sales year maxsale prisic
>> 1001 1 25.395 1990 25.395 0
>> 1001 1 32.007 1991 32.007 0
>>
>> I could not figure out why prisic is 0, so I compute the diffderence
>> (sales-maxsale), it shows a very small negative number , and the data
>> dictionary shows sales format float %12.0g, and maxsale format float
>> %9.0g
>>
>> what should I do to correct this?
>>
>> thanks!!!
>>
>> Rochelle
>> *
>> * 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/
>
>
>
> --
> ---------------------------------
> Maarten L. Buis
> WZB
> Reichpietschufer 50
> 10785 Berlin
> Germany
>
> http://www.maartenbuis.nl
> ---------------------------------
> *
> * 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/