Hello,
I am currently in the process of taking old do-files written under
Stata 9 and converting them to Stata 10.
In one case, the old file contains the following code:
* Merge in codes
foreach var in body_part cause nature_of_injury {
sort `var'_code
merge `var'_code using `PROJECT_ROOT'/data/`var'_codes, uniqusing nokeep
tab _merge
drop _merge
move `var' `var'_code
}
To be clear, there are .dta files named "body_part_codes.dta"
"cause_codes.dta" and "nature_of_injury_codes.dta" which have two
variables, one (called "body_part_code", "cause_code", or
"nature_of_injury_code", depending on which file it is) being a code
stored as a string and the second ("body_part", "cause", or
"nature_of_injury") being a string corresponding to what the code
means (e.g. "Head", "Fall", "Sprain").
For example, an excerpt from body_part_codes.dta:
+---------------------------------+
| body_part_code body_part |
|---------------------------------|
1. | 02 Abdomen |
2. | 04 Spinal Cord |
3. | 05 Brain |
4. | 06 Ankles |
5. | 09 Arms |
|---------------------------------|
6. | 10 Head - Multiple Head |
7. | 11 Head - Skull |
8. | 12 Head - Brain |
9. | 13 Head - Ear(s) |
10. | 13 Back |
Note that 13 is a duplicate.
When this program was run on a Windows XP machine with Stata 9.2 (born
July 20 2007), this caused no errors. However, when I run the same
code on my Vista machine with Stata 10, it throws an error because the
variable body_part_code is not unique in the using file. Looking at
the body_part_codes file, I find that this is in fact correct, that
there are some codes that are duplicated. For example, "03"
corresponds both to "Head" and "Back".
Why wasn't this throwing an error in Stata 9.2? When I version the
do-file to Stata 9 and run it with Stata 10, it still throws an error.
Was this a bug? I am worried that there may be other problems with our
files that are not being flagged as they are supposed to be.
I am baffled, and I appreciate any help you can give me.
Brian
*
* 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/