What Stata is telling you is that the variable UNIT is inconsistent across some of your data sets. In one of them it is a string, and in another it is numeric. So you need to decide which of those you want it to be. Generally speaking when a variable that is usually numeric comes in as a string after -import excel- it is because some of the Excel cells in that column contain non-numeric content. For example, there might be an "N/A" or "--" or "> 4" or something like that. So you have to go back to the individual files and see what's there and then decide how you want to handle this. You might want to, for example, change things like "N/A" to Stata's missing value. So in that file you could -destring UNIT, replace ignore("N/A")- to do that. On the other hand with something like > 4 you might feel that it is necessary to retain that information, so in the files where UNIT is numeric, you might convert it to string: -tostring UNIT, replace-. Anyway, before you can successfully -merge- all these files, you will have to have UNIT as string in all files or as numeric in all files. You can't mix the types.
In general, in Stata, it is not a good practice to mass -merge- a bunch of files, precisely because the probability of encountering incompatibilities of this nature is pretty high, even with professionally curated data from reputable sources. It is better to import each sheet into a separate file and then carefully examine the files for incompatibilities and fix them. Then merge the fixed files together. There is a nice little tool for ferreting out incompatibilities: the -precombine- command written by Mark Chatfield. To get it, run -findit precombine- and then click on the link "dm0081 from http://www.stata-journal.com/software/sj15-3" and then click on "(click here to install)". I strongly recommend using it to detect these problems ahead of time.
In general, in Stata, it is not a good practice to mass -merge- a bunch of files, precisely because the probability of encountering incompatibilities of this nature is pretty high, even with professionally curated data from reputable sources. It is better to import each sheet into a separate file and then carefully examine the files for incompatibilities and fix them. Then merge the fixed files together. There is a nice little tool for ferreting out incompatibilities: the -precombine- command written by Mark Chatfield. To get it, run -findit precombine- and then click on the link "dm0081 from http://www.stata-journal.com/software/sj15-3" and then click on "(click here to install)". I strongly recommend using it to detect these problems ahead of time.
Comment