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 at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: Unable to use "replace" on specific values (but others work ok)


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Unable to use "replace" on specific values (but others work ok)
Date   Thu, 18 Oct 2012 23:59:33 +0100

That's good news, as it rules out even more bizarre fancies on what
may be happening.

A clean-up command that should serve to protect yourself is

replace mystr  = trim(subinstr(mystr, char(160), " ", .))

Another approach is to put the occupation codes into a Stata dataset,
clean them once and for all, and use an approach akin to that
explained in

FAQ     . . . . . . . . . . . Defining group characteristics to create subsets
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C. F. Baum
        12/01   How do you efficiently define group characteristics
                in your data in order to create subsets?
                http://www.stata.com/support/faqs/data/characteristics.html

Nick

On Thu, Oct 18, 2012 at 11:43 PM, Anna Reimondos <areimondos@gmail.com> wrote:
> Thanks for the tip about filefilter. Will definitely use that!
>
> I have finally discovered what is happening I think. As mentioned I am
> working with occupation coding.
>
> *Long answer
> Each respondent is manually coded based on what they described their
> occupation to be in an open text question. As there are 2000+ cases, I
> have tried to streamline the procedure by first working from an excel
> spreadsheet.
>
> The excel spreadsheet has a column for the id of the respondent,
> another couple of columns with the occupation description. Finally
> there is a column for the ANZSCO code which I am filling in. The code
> is derived by searching for occupations on the Australian Bureau of
> Statistics website.
> For example I search for a 'massage therapist' and find that the code
> is 411611.
> http://www.abs.gov.au/ausstats/abs@.nsf/Product+Lookup/1220.0~First+Edition,+Revision+1~Chapter~UNIT+GROUP+4116+Massage+Therapists
>
> I am selecting and copying the code directly from the website.
> Sometimes I am accidentaly also copying a space after the numbers.
>
> Afterwards in Excel I use concatenate to create a list of commands,
> e.g. replace anzscovariable=411611 if id==6  etc. Because the space
> after the massage therapist code is now also getting incorporated
> getting copied this is what is creating the problem.
>
> *Short answer
>  I am copying numbers from the web, pasting them into excel,
> generating the commands, and then pasting them into a do-file and thus
> probably introducing the bad characters in the process.
>
> On Wed, Oct 17, 2012 at 4:57 AM, Nick Cox <njcoxstata@gmail.com> wrote:
>>
>> I believe you, but I see nothing different. I guess that others will
>> see what you see if and only if their mailer behaves like yours.
>>
>> But the more tools there are to spot this kind of thing, the better.
>> Laura is signalling that your mailer may make odd characters evident.
>> The same is true of many good text editors.
>>
>> Nick
>>
>> On Tue, Oct 16, 2012 at 6:14 PM, Laura Gibbons
>> <gibbonsl@u.washington.edu> wrote:
>> > I know the problem has been solved, but I just wanted to note that in my
>> > DOS-based email client, the problem is obvious (see how it displays below).
>> >
>> >
>> > On Tue, 16 Oct 2012, Anna Reimondos wrote:
>> >
>> >> Hello statalisters,
>> >> I am currently coding occupations of respondents in a survey to the
>> >> Australian New Zealand Standard Classification of Occupations
>> >> (ANZSCO).
>> >> A rather odd thing is happening where I am able to assign the ANZSCO
>> >> code in some cases, but not others!
>> >>
>> >>
>> >> For example in the code below there is no problem assigning the value
>> >> 121312 to case 1, and no problem assigning the value 121314 to case 2.
>> >> However for case 3 who I want to give the code 121313 the code returns
>> >> an error message '121313 invalid name' r(198).
>> >>
>> >> clear
>> >> set obs 3
>> >> gen var1=.
>> >> replace var1=121312 if _n==1
>> >> replace var1=121314 if _n==2
>> >>
>> >> replace var1=121313 if _n==3  //Problem
>> >>
>> >> The problem is not just with 121313, but it also does not seem to like
>> >> 254499, 323112 and 821311 among others.
>> >> I don't understand what is happening!
>> >>
>> >> I am using Stata 12.1, but have also tried this in 11.2 and get the
>> >> same error code.
*
*   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