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: problem with addition in var generation
From
Nick Cox <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: problem with addition in var generation
Date
Thu, 7 Nov 2013 08:38:38 +0000
In addition to other pertinent comments: In case anyone is thinking
otherwise, -format- merely controls how values are displayed. It has
precisely zero effect on how they are stored.
Nick
[email protected]
On 7 November 2013 04:46, Andrew Hovel <[email protected]> wrote:
> Thanks for the help! This should sort it out.
> I'll use the string methods for id's in the future as you suggest.
>
> On Wed, Nov 6, 2013 at 10:26 PM, Steve Samuels <[email protected]> wrote:
>>
>> The apparent error arises from your failure to set the precision correctly when you generated the fip11 variable.
>>
>>
>> . gen fip11 = 0
>>
>> created a variable of storage type float
>>
>> . generate long fip11 = 0
>>
>> or
>>
>> . generate double fip11 = 0
>>
>> would have prevented the problem.
>>
>>
>> Type "help precision" and "search precision, all" for Bill Gould's blogs.
>>
>> But I agree with Billy that it is poor practice to create these pseudo-ids as numbers.
>>
>> Steve
>>
>>
>> On Nov 6, 2013, at 11:09 PM, William Buchanan wrote:
>>
>> Why are you adding these values in the first place? As ID variables it would be much easier to treat the 5-digit and 6-digit components as strings and concatenate the strings to form your 11 character ID variable. Also, if you're working with geographic IDs in the US it would probably be easier and more consistent to use variables that are standardized across multiple datasets/TIGER files.
>>
>> Sent from my iPhone
>>
>>> On Nov 6, 2013, at 21:39, Andrew Hovel <[email protected]> wrote:
>>>
>>> Hello All,
>>>
>>> I am having issues with Stata performing simple addition when I create a
>>> variable. I am using Stata 12 for windows.
>>>
>>> The issue is straight-forward on the face of it: Stata is adding
>>> incorrectly.
>>>
>>> Background:
>>> I am trying to construct pseudo fips codes by adding the tract code to the
>>> 5 digit state-county fips. For instance, 06037 denotes Los Angeles County,
>>> CA, so I would add 6037000000 to the six-digit tract fips code to form a 10
>>> digit code-- 11 digits for states later in the alphabet with fips id's
>>> above 10.
>>> I have two variables formatted %15.0f, fip11 and tract. tract is 6 digits
>>> long and uniquely identifies the Census tracts in my dataset.
>>>
>>> .gen fip11 = 0
>>> .replace fip11 = 6001000000 + tract if T_COUNTY == "001"
>>> .replace fip11 = 6037000000 + tract if T_COUNTY == "037"
>>> .replace fip11 = 6073000000 + tract if T_COUNTY == "073"
>>>
>>> When I run this, I get something like this:
>>> -tract- -fip11-
>>> 400200 6001400320
>>> 400500 6001400320
>>> 400400 6001400320
>>> 400300 6001400320
>>>
>>> This happens for others in ascending order.
>>>
>>> I noticed a trend in the way they are adding. Cases repeat values for fip11
>>> usually about 4 or 5 times in a row. After 4 or 5 cases, the value
>>> increases by 512 each time.
>>>
>>> For example:
>>>
>>> -tract6- -fip11-
>>> 400300 6001400320
>>> [3 cases]
>>> 400100 6001400320
>>> 400900 6001400832
>>> [3 cases]
>>> 400600 6001400832
>>> 401300 6001401344
>>> [3 cases]
>>> 401400 6001401344
>>> 401800 6001401856
>>> [3 cases]
>>> 401600 6001401856
>>> 402400 6001402368
>>> [3 cases]
>>> 402200 6001402368
>>> 402900 6001402880
>>>
>>> Has anyone seen this problem before? I have had this issue in the past. I
>>> am guessing I must have some sort of setting wrong to cause the addition to
>>> occur like this.
>>> *
>>> * 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/
>>
>>
>> *
>> * 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/
*
* 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/