Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: asarray_keys() error


From   Matthew White <mwhite@poverty-action.org>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: asarray_keys() error
Date   Thu, 16 May 2013 17:22:36 -0400

Hi Sergiy,

Thank you for your reply. The help file on -asarray()- suggests that
it can handle collisions, though maybe it can't. It seems to me that
the only function that isn't working is -asarray_keys()-: even after I
use the keys ("type", "keep") and ("name", "char"), -asarray()- works
fine. I'm considering just creating my own matrix of keys:

mata:
A = asarray_create("string", 2)
// Create my own matrix of keys.
keys = "type", "keep"
asarray(A, keys[1,], 1)
keys = keys \ "name", "char"
asarray(A, keys[2,], 2)
// -asarray()- still works.
asarray(A, keys[1,])
asarray(A, keys[2,])
// I have the list of keys.
keys
// Though -asarray_keys()- still doesn't work.
asarray_keys(A)
end

Maybe I'll write a function that runs -asarray()- with a certain key
and adds the key to matrix keys, in order to reduce the number of
lines and to make sure that keys is always updated.

Best,
Matt

On Thu, May 16, 2013 at 10:03 AM, Sergiy Radyakin
<serjradyakin@gmail.com> wrote:
> Dear Matthew,
>
> I can confirm the problem also reproducible in Stata 11.2.
>
> The problem is likely the collision of hashes generated with hash1()
> function. Such collisions are unlikely, though possible. This is also
> consistent with your observation of changing the keys does not
> generate the error. Note that the problem does not occur if you add a
> "_" (an underscore) to each of your keys. (but this is data-dependent,
> there will be a combination that will collide again, but perhaps you
> will be lucky not to encounter it in your data). Would this would be a
> suitable workaround for you?
>
> Best, Sergiy Radyakin
>
> mata:
> A = asarray_create("string", 2)
> asarray(A, ("_type", "_keep"), 1)
> asarray(A, ("_name", "_char"), 2)
> asarray_stats(A)
> asarray_keys(A)
>
> end
>
>
> : asarray_keys(A)
>            1       2
>     +-----------------+
>   1 |  _name   _char  |
>   2 |  _type   _keep  |
>     +-----------------+
>
>
> On Wed, May 15, 2013 at 5:35 PM, Matthew White
> <mwhite@poverty-action.org> wrote:
>> Hi Statalist members,
>>
>> I'm running the following commands in Stata 12.1 SE:
>>
>> mata:
>> A = asarray_create("string", 2)
>> asarray(A, ("type", "keep"), 1)
>> asarray(A, ("name", "char"), 2)
>> asarray_keys(A)
>>
>> However, -asarray_keys()- issues the following error message:
>>
>> asarray_keys_dup():  3201  vector required
>> asarray_keys():     -  function returned error
>> <istmt>:     -  function returned error
>>
>> If I run -asarray()- for just one key, -asarray_keys()- does not
>> result in an error. For example:
>>
>> mata:
>> A = asarray_create("string", 2)
>> asarray(A, ("type", "keep"), 1)
>> asarray_keys(A)
>> end
>>
>> If I change any one of the elements of the keys, -asarray_keys()- also
>> does not result in an error:
>>
>> mata:
>> A = asarray_create("string", 2)
>> asarray(A, ("example", "keep"), 1)
>> asarray(A, ("name", "char"), 2)
>> asarray_keys(A)
>> end
>>
>> Any suggestions would be appreciated.
>>
>> Thank you,
>> Matt White
>>
>> --
>> Matthew White
>> Senior Project Associate
>> Innovations for Poverty Action
>> 101 Whitney Avenue, New Haven, CT 06510 USA
>> www.poverty-action.org
>> *
>> *   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/



-- 
Matthew White
Senior Project Associate
Innovations for Poverty Action
101 Whitney Avenue, New Haven, CT 06510 USA
www.poverty-action.org
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index