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: Expanding characteristics of variables with 32-character names


From   Matthew White <[email protected]>
To   [email protected]
Subject   Re: st: Expanding characteristics of variables with 32-character names
Date   Tue, 6 Aug 2013 21:43:20 -0400

Thank you, Sergiy, for the confirmation. I'll go ahead and use the
-:char- extended macro function and Mata's -st_global()-.

Best,
Matt

On Mon, Aug 5, 2013 at 7:06 PM, Sergiy Radyakin <[email protected]> wrote:
> Matt,
> I can reproduce the problem both in Stata 9 and Stata 12 with the
> following code:
>
> clear
> forval i=1/32 {
>   local vn=substr("abcdefghijklmnopqrstuvwxyz0123456789",1,`i')
>   assert strlen(`"`vn'"')==`i'
>   generate `vn'=999
>   char `vn'[`vn'] 1
>   display `"`i' `vn'"'
>   di `"`:char `vn'[`vn']'"'
>   assert `:char `vn'[`vn']'==1
>   di `"{``vn'[`vn']'}"'
>   assert ``vn'[`vn']'==1
> }
> describe
>
> I can add that the Mata's st_global() produces correct result, so
> that's another alternative. And I can add that I never used the
> simplified access to characteristics as you used varname[varchar] in
> Stata, always using a char macro expansion or recently more often the
> Mata approach.
>
> In my opinion it looks like a bug. I recall older specifications of
> the dta file format had a typo around the characteristics storage
> description. This was corrected around v11, but the typo came back in
> the Stata 13th help for data file description (I have notified
> StataCorp techsupport on  2013.06.13). Not sure if this is related.
>
> Best, Sergiy Radyakin
>
> On Mon, Aug 5, 2013 at 5:14 PM, Matthew White <[email protected]> wrote:
>> Hi Statalist users,
>>
>> Using Stata 13 on Windows 7, I'm attaching a characteristic to
>> variables and then using single quotes to expand the characteristic.
>> For example:
>>
>> sysuse auto, clear
>> char foreign[Y] 1
>> char list foreign[]
>> display `foreign[Y]'
>>
>> However, I'm having trouble when the variable name is 32 characters long:
>>
>> sysuse auto, clear
>>
>> char foreign[Y] 1
>> char list foreign[]
>> display `foreign[Y]'
>>
>> local var : di _dup(32) "x"
>> rename foreign `var'
>>
>> char list `var'[]
>> display ``var'[Y]'
>>
>> `var'[Y] still exists, but ``var'[Y]' doesn't expand to anything. Has
>> anyone seen this problem before?
>>
>> I can get around it by using the -:char- extended macro function:
>>
>> display `:char `var'[Y]'
>>
>> This correctly displays 1. However, I'd prefer to use the ``var'[Y]'
>> syntax if possible.
>>
>> Thank you,
>> Matt
>>
>> --
>> 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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index