Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Why can't I convert variables from string to numeric?

    I've imported the data from excel, there the data was numeric. While importing it, Stata recognizes it as strings and gives no reaction when I try to convert it. Please, can anyone help me?? What the problem might be?

  • #2
    So, you would like advice on troubleshooting some code which you have not shown, applying to data which you have not shown. While I sometimes enjoy imagining data sets and writing code for them, it, often as not, turns out not to work with the real data. It would be a better use of both of our energies if you were to post an example of the data using the -dataex- command. Also show the exact code that you tried, along with what Stata gave you back (including any error messages). Then, if it is not obvious why what you got isn't what you need, explain what you were hoping to get instead.

    It is particularly important in this situation that your example data be posted using -dataex-. This is because the details of how the data is stored and formatted and labeled will be crucial to finding the correct solution. -dataex- is the only good way to assure that those details are faithfully and fully conveyed.

    If you are running Stata version 15.1 or a fully updated version 14.2, you already have the -dataex- command in your official installation. Otherwise, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. You will find that not only does it provide the most helpful display of the example data for those who want to help you, but it is also quicker and easier on your end than any other way of showing the data.

    Comment


    • #3
      Welcome to Statalist, Lucy.

      Clyde gives good advice.

      There is one common problem importing data from Excel that might cause your data to not be recognized as numeric. If Stata sees any character data in the column of numbers, it imports the whole column as a string variable. Spreadsheet users often enter missing values in the data as "NA" - does your data have any of that going on? Does the first row (or more) in Excel contains names or column headings? Stata will not skip that unless it is told to, or is told to use one of the rows as variable names.

      But again, we don't know what your worksheet looks like or how you imported it. Did you just type an import excel command to get your data imported? If so, one thing that might help you resolve your problem is to use Stata's menus to interactively import the worksheet. From the File menu choose Import, then from the popup on the right choose Excel spreadsheet. You'll get an interactive dialog box that lets you choose your data and that previews how it is going to be imported. And there are a number of options to play with. Try different options, see if you can fiddle around enough to get your data imported the way you want. And the neat thing is, your results window will show the Stata command generated by the dialog box, so you can copy it and use it the next time you have to import the file or one a lot like it.

      But if these hints don't help, take Clyde's advice to heart. It's drawn from the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post. You might review it, noting especially sections 9-12 on how to best pose your question.

      It all comes down to the following: the more you help others understand your problem, the more likely others are to be able to help you solve your problem.

      Comment

      Working...
      X