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: problem with addition in var generation


From   Fernando Rios Avila <[email protected]>
To   [email protected]
Subject   Re: st: problem with addition in var generation
Date   Wed, 6 Nov 2013 23:20:31 -0500

Andrew,
You are incorrect. Stata is doing the summing it correctly, and
storing the information the best it can in float variable.
I suggest you to start by creating your fips variable as double.
gen double fip11=0
That will handle your problem.
Best regards

On Wed, Nov 6, 2013 at 11:16 PM, Andrew Hovel <[email protected]> wrote:
> William, thanks for your suggestions, but I have started using this
> method because of discrepancies in some datasets. I am using a dataset
> that had poorly formatted Tract ID's so doing everything numerically
> was easier.
>
> In any case, your comments are beside the point that is the larger
> issue at hand here: Stata is not performing addition correctly.
>
> On Wed, Nov 6, 2013 at 10:09 PM, William Buchanan
> <[email protected]> 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/


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