Announcement

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

  • Excel data input

    Hi everyone!

    It is probably not the hardest question, but I couldn't find it by looking it up on google. I am trying to upload a data file from excel using the code:

    import excel using zip_code_database2.xls, firstrow

    The data as can be seen in the file attached contains zip codes of which some start with 00.... or 0.... . When uploading the file however stata does not include the leading 0's in the file. Is there a way to automatically and correctly import the data leaving the leading 0's intact.

    Kind regards,
    Rick
    Attached Files

  • #2
    Rick, this issue is likely from the format setting in your original Excel file. But you may import the data first and then add zeros in front of the zip code.

    Code:
    import excel using zip_code_database2.xls, firstrow allstring
    replace zip = "0"*(5-length(zip)) + zip if !mi(zip)

    Comment


    • #3
      Thanks again!

      Comment

      Working...
      X