Statalist


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

st: Numeric variable (in Excel) with some string cases: To destring without loosing the text information


From   Jia Xiangping <[email protected]>
To   statalist <[email protected]>
Subject   st: Numeric variable (in Excel) with some string cases: To destring without loosing the text information
Date   Mon, 6 Apr 2009 09:02:45 +0800

Hi all,

I am working on a second-hand data in Excel format. Most of the
variables are numeric while some are strings. For those numeric
variables, some cases were inputted as strings that includes some
texts for explaining the data when conducting the survey .  While I
need numeric information, I want to check those text information one
by one and to look up in details. Dirty work but necessary.

Here is the way I did.
1) In Excel, I add one new obs as the first obs

id var1 var2 var3
    abc abc  abc
1   23   111  119
2   5     91     89
3  1dog   2cat  4dog

2) Infile the excel data into Stata (for just copy them into Stata).
Since all variables are identified as strings, no information lost.

3) In Stata,
verson 10
drop if id==.   //drop the newly added 1st obs
local xlist var1 var2 var3
foreach v of local xlist {
	destring `v', gen(j`v') force    //generate a numeric variable by
dropping those text information
	list id `v' j`v' if `v'~="" & j`v'==.   // check those text cases
	}

PROBLEM. The syntax works well; the variables are destringed. But the
annoy thing is that the results of the last line is NOT displayed.
But when I type variables one by one, for example "list id var1 jvar1
if var1~=""&jvar1==.", the text cases are displayed
     +-------------------+
     | id   var1   jvar1 |
     |-------------------|
  3. |  3    dot       . |
     +-------------------+

Since there are a great number of variables, no way to do it one by
one. Could someone tell me what's wrong with the syntax? Why the last
line does not perform to show the text cases?

Many thanks.


-- 
Xiangping Jia
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index