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: RE: Problem identifying a specific value of a string variable


From   Sergiy Radyakin <[email protected]>
To   [email protected]
Subject   Re: st: RE: Problem identifying a specific value of a string variable
Date   Thu, 9 Sep 2010 20:02:01 -0400

Or more directly:
levelsof col1_d

If you suspect non-printable characters, the fastest way is usually

mata ascii(st_sdata(3,1))

         1     2     3     4     5     6     7     8     9    10
    +-------------------------------------------------------------+
  1 |   65    77    67    32    83   112   105   114   105   116  |
    +-------------------------------------------------------------+

(shows the decimal byte codes of the string value in the third
observation of the first variable, here for auto.dta)

Best, Sergiy




On Thu, Sep 9, 2010 at 6:38 PM, Kieran McCaul <[email protected]> wrote:
> ...
>
> have you tried
> egen x = group(col1_d)
>
> This will give you a numeric variable, x, where each value corresponds to the string values of col1_d.  Then find the value of x that corresponds to 2e in col1_d.
>
>
>
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On Behalf Of Brad Humphreys
> Sent: Friday, 10 September 2010 5:19 AM
> To: [email protected]
> Subject: st: Problem identifying a specific value of a string variable
>
> Dear Statalisters,
>
> I have a string variable that I cannot seem to get Stata to perform
> operations on.  This is part of a multiple step string to numeric
> conversion. The string variable is col1_d
>
> . desc col1_d
>
>              storage  display     value
> variable name   type   format      label      variable label
> -------------------------------------------------------------------------------------------
> col1_d          str5   %9s
>
> . tab col1_d
>
>     col1_d |      Freq.     Percent        Cum.
> ------------+-----------------------------------
>         2e |          1        0.00       29.09
>
> The variable takes many values.  I have not reported the rest, as I
> want to keep them. I can't get that observation, or about 10 more,
> identified, using -list-, -drop-, or -replace-.  I tried:
>
> . l if col1_d=="2e"
>
> Returns nothing.  I tried:
>
> . drop if col1_d=="2e"
> (0 observations deleted)
>
> I tried -trim-, -ltrim-, strltrim- on the variable, thinking there
> could be leading blanks in there.  No luck.  I tried copying the
> offending value for col1_d from the data editor into the do file
> command.  No luck.  The variable col1_d is created using this command
>
> gen col1_d=col1 if frac_col1==0
>
> where col1 is a string variable.
>
> . desc col1
>
>              storage  display     value
> variable name   type   format      label      variable label
> -------------------------------------------------------------------------------------------
> col1            str10  %10s
>
>
> Any help would be appreciated.   I am at wits end.
>
> Brad Humphreys
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/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/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/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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