Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Re: destringing

From   Suzy <[email protected]>
To   [email protected]
Subject   Re: st: Re: destringing
Date   Sat, 28 Aug 2004 12:26:36 -0400

Dear Mike - Yes, I don't usually tab on one variable - I just gave a quick example so the output could be read. The problem was indeed the obvious - which was to enclose these codes in quotations...which I just plain had overlooked....

You've been very helpful and I'm grateful for the kind patience you all have shown...

Michael S. Hanson wrote:

On Aug 28, 2004, at 11:30 AM, Suzy wrote:

. tab dxcode1 if dxcode1==V3000
V3000 not found

In your -if- statement, you told Stata to compare the variable dxcode1 with the variable V3000. And Stata responded: "V3000 not found" because you don't have a variable called V3000.

And this....

tab dxcode1 if dxcode1==27500  (just numeric)
type mismatch

Stata knows from your -infix- command that the data type of variable dxcode1 is a string (specifically, str5 -- a 5-character string). You then asked Stata to compare a string variable with a numerical value -- but since these are different data types, Stata responded "type mismatch".

That's why I then went ahead and used the destring (and force) option...which made the dash and alpha-numerics disappear as missing datapoints - but did allow me to read the pure numeric numbers under these variable names.

Which seems unnecessary. Have you tried:

tab dxcode1 if dxcode1 == "V3000"
tab dxcode1 if dxcode1 == "27500"

(By the way, are you sure you aren't interested in tabulating the values of *another* variable when dxcode1 takes on particular values?)

Stata technicians did not tell me that when I added the str5 and str4 to those variables during infix - that my data would not be able to be read. So this is the full story.

They did not tell you that because that would not be a correct statement. You can read the data -- and you can use conditional statements by telling Stata to compare string variables with strings (i.e. values in "quotes").

Hope this helps.

-- Mike

* For searches and help try:

*   For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index