Announcement

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

  • import delimited "could not name variables specified" error

    Hi,

    I have not been able to resolve an error with an import delimited syntax. The error is r(198) "could not name variables specified".

    Code:
    * i have tried lots of different variations.  here are the two simpliest
    import delimited zip_code using "TTS_LBNL_public_file_19-Oct-2020_p1.csv", varnames(1) stringc(_all) clear
    import delimited zip_code using "TTS_LBNL_public_file_19-Oct-2020_p1.csv", varnames(1) delim(",") stringc(_all) clear
    
    * the full command I wanted to use and started with is this:
    
    import delimited zip_code state system_size_DC customer_segment installation_date module_quantity_1    module_quantity_2 module_quantity_3 nameplate_capacity_module_1    nameplate_capacity_module_2    nameplate_capacity_module_3 using TTS_LBNL_public_file_19-Oct-2020_p2.csv, varnames(1) delim(",") stringc(_all) clear
    
    * all the variations I have tried result in this error
    I was not able to find a discussion of this error online. I suspect it is something very simple I am failing to see

    FYI the file I am trying to import is downloadable here: https://emp.lbl.gov/tracking-the-sun

    Any ideas?

    Thanks in advance,

    Ben


    Ben Hoen
    Research Scientist
    Lawrence Berkeley National Laboratory

  • #2
    Try it without renaming the columns in the import statement:

    Code:
    import delimited using  "C:\Users\scott\Desktop\lbnl_publicdatafile_dpv_2020_update\TTS_LBNL_public_file_19-Oct-2020_p2.csv" , /// 
    clear stringc(_all) varnames(1) delim(",")
    keep zip_code state system_size_dc customer_segment installation_date /// 
        module_quantity_1 module_quantity_2 module_quantity_3 /// 
        nameplate_capacity_module_1 nameplate_capacity_module_2  ///
        nameplate_capacity_module_3

    Comment


    • #3
      That worked! Thanks Scott!

      So is this why it had an error? It was not clear which columns to import (without a colrange[]) and I was giving it only a small number of column names based on the large number of columns in the file. The names, which corresponded to the varnames in row 1, were not taken into account.

      Any idea if it is possible to give it certain columns to import? That was my goal, so as to speed up the import.

      Comment


      • #4
        Any idea if it is possible to give it certain columns to import? That was my goal, so as to speed up the import.
        No, it is not possible. The list of variable names following the delimited and preceding the using is not a list of variable names to import. Instead, it is a list of variable names to assign to the imported columns. So - I surmise - after importing all the columns, it tried to rename the first variable to zip_code ... which already existed as a variable in the dataset. The cryptic error message is consistent with that.
        Code:
        . copy https://www.stata.com/examples/auto.csv auto.csv
        
        . type auto.csv, lines(1)
        make,price,mpg,rep78,foreign
        . import delimited gnxl using auto.csv
        (encoding automatically selected: ISO-8859-1)
        (5 vars, 10 obs)
        
        . ds
        gnxl     price    mpg      rep78    foreign
        
        . clear
        
        . import delimited mpg using auto.csv
        (encoding automatically selected: ISO-8859-1)
        could not name variables specified
        r(198);

        Comment


        • #5
          That makes a lot of sense!

          Comment

          Working...
          X