Announcement

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

  • Importing variable with special characters, strings and numbers

    Dear Stata users,

    I am experiencing problems in importing a variable from a csv file. This variable values contains #, %, numbers and strings (example "1MISE#CSEE-N0115-CZ-1"). The problem is that these are imported all as numeric missing values. My guess is that special characters (# - %) cause the problem. Do you have a fix for this? My idea is to modify all csv's using other programs but I would rather do this directly importing the variable directly in Stata. I am currently using Stata14.

    Thank you in advance for your answer.

  • #2
    Can you show an example of your data here, along with the exact import command you used? I'd suggest the first new lines of the data file, along with some of the problem observations, as a good example.

    Comment


    • #3
      Dear Mike,
      thank you for your answer. Here is an example of my data:
      1CA#10C12007IT161PO001
      1CA#13C12007IT161PO001
      1CA#14C12007IT161PO001
      1CA#15C12007IT161PO001
      1CA#16C12007IT161PO001
      1CA#5C12007IT161PO001
      1CA#7C12007IT161PO001
      1CL#100086

      command used: import delimited ".csv", clear delimiter(";") varnames(1) encoding(UTF-8)

      They are all imported as missing .

      I have tried to do: import delimited ".csv", clear delimiter(";" "#") varnames(1) encoding(UTF-8)
      and it imports the values successfully as strings in different variables. I can do this, join the vars adding the # but importing all directly would be preferred

      Comment


      • #4
        try the "stringcols(_all)" option and then deal with the variables from within Stata; please use -dataex- in the future for showing data samples and please put the -dataex- results within CODE blocks - these are explained in the FAQ

        Comment


        • #5
          Rich's suggestion is a good one. However, your example works fine for me. I'd suspect that you will have to include more variables (which I presume you have) than just this one to have a file that will create a problem.

          Comment

          Working...
          X