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]
st: Problem with -infix- with if qualifiers and strings?
From
Jorge Eduardo Pérez Pérez <[email protected]>
To
"[email protected]" <[email protected]>
Subject
st: Problem with -infix- with if qualifiers and strings?
Date
Tue, 12 Nov 2013 17:13:33 -0500
Dear Statalist.
I have noticed weird behavior regarding -infix- and data where the
variable type may change per line. -infix- is not reading the dataset
properly.
Here's an example. My dataset is:
10ABC
20321
10ZYX
20654
If I try to read the lines that start with 10 and the remainder as a
string, everything works:
. clear
. infix type 1-2 str text 3-5 if type==10 using test.txt
(2 observations read)
. list
+-------------+
| type text |
|-------------|
1. | 10 ABC |
2. | 10 ZYX |
+-------------+
But if I try to read the lines that start with 20, where the remainder
is a number, Stata seems to be trying to read the lines that start
with 10 as well, producing a "cannot be read" message and , worse,
dropping observations from my data!
. clear
. infix type 1-2 number 3-5 if type==20 using test.txt
'ABC' cannot be read as a number for number[1]
'ZYX' cannot be read as a number for number[2]
(1 observations read)
. list
+---------------+
| type number |
|---------------|
1. | 20 321 |
+---------------+
I have replicated this in both Stata 12.1, Windows 7 and 13.1 on
Windows 8. Can someone replicate to see if this is a bug, or am I
missing something? In the meantime I will read my variables as strings
and destring afterwards.
Thanks!
--------------------------------------------
Jorge Eduardo Pérez Pérez
Graduate Student
Department of Economics
Brown University
*
* 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/