Announcement

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

  • Import First Row as Variable Name Not Working

    Hi All,

    I am trying to import an excel spreadsheet with 257 observations into Stata. I have previously imported the same spreadsheet, setting the cell range as A2:GO257 and importing the first row as variable names.

    However, I have only added 2 columns since last use and they are have fairly standard all alphabetic character names and am now unable to import with first row as variable name. If I try to use any other row it will give me the option, but when I want to use row 2 it is graying out the option as shown below [NB, I deleted the top row from the excel sheet in case that was causing the problem].

    I'm not sure why this is happening, any help would be much appreciated.

    Click image for larger version

Name:	Stata problem.GIF
Views:	1
Size:	31.4 KB
ID:	1394816

  • #2
    I don't replicate your problem. Using the two attached Excel workbooks, which I believe replicate your conditions, Stata does not have a problem importing the worksheets beginning with the variable names in the second row.

    "Sheet1" in the first workbook ("GO257.xlsx") is before adding two additional columns, and in the second workbook ("GQ257.xlsx") is after adding the two columns.

    Nothing is greyed out on the GUI, and the code below runs without a hitch (see the output below the code).
    Code:
    version 14.2
    
    clear *
    set more off
    
    import excel GO257.xlsx, sheet(Sheet1) cellrange(A2:GO257) firstrow
    describe v197, simple
    
    import excel GQ257.xlsx, sheet(Sheet1) cellrange(A2:GO257) firstrow clear
    describe v197, simple
    
    import excel GQ257.xlsx, sheet(Sheet1) cellrange(A2:GQ257) firstrow clear
    describe v197-v199, simple
    
    exit
    .ÿversionÿ14.2

    .ÿ
    .ÿclearÿ*

    .ÿsetÿmoreÿoff

    .ÿ
    .ÿimportÿexcelÿGO257.xlsx,ÿsheet(Sheet1)ÿcellrange(A2:GO257)ÿfirstrow

    .ÿdescribeÿv197,ÿsimple
    v197

    .ÿ
    .ÿimportÿexcelÿGQ257.xlsx,ÿsheet(Sheet1)ÿcellrange(A2:GO257)ÿfirstrowÿclear

    .ÿdescribeÿv197,ÿsimple
    v197

    .ÿ
    .ÿimportÿexcelÿGQ257.xlsx,ÿsheet(Sheet1)ÿcellrange(A2:GQ257)ÿfirstrowÿclear

    .ÿdescribeÿv197-v199,ÿsimple
    v197ÿÿv198ÿÿv199

    .ÿ
    .ÿexit

    endÿofÿdo-file


    .


    What do you have in your first row, especially in the two new columns?
    Attached Files

    Comment


    • #3
      Thanks so much for all your effort.

      Weirdly enough, if I go back to a version of the datasheet where I only had one variable entered, it works fine. If I delete the last added variable from the new datasheet it still does not work. This is super perplexing.

      The new variable is a string variable that just contains comments about the data I have been analysing for my reference.

      Edit: I am also trying it on a different computer and getting the same problem

      Edit: I just copy pasted the same data into a different spreadsheet and now it works. Can't for the life of me understand what the problem is.
      Click image for larger version

Name:	dodgy stata import.PNG
Views:	1
Size:	10.1 KB
ID:	1394830

      Last edited by Rahul Muthalaly; 25 May 2017, 19:35.

      Comment


      • #4
        I just ran into the same problem trying to import an excel file and being unable to import first row as variable names. Even if i selected the box before going to the worksheet I wanted to import (which would have the box selected when I imported the sheet, but still wouldn't let me click on the box and toggle it off or on), My variable names were imported as generic alphabetical characters. When I examined the sheet I was trying to import in the preview window (just below where your screenshot is cut off), I noticed I had many columns of missing data unintentionally included as part of the worksheet. I opened excel, deleted these columns, and the problem was solved. I could then import the first row as variable names.

        Comment


        • #5
          This seems to happen if there is "something" in the columns outside your data. This might just be some highlighting...guess it's because there are no variable names at the top of those cells. Delete the extraneous material to the right of your spreadsheet and it seems to work!

          Comment


          • #6
            This also seems to happen when the variables in the first row of the excel file include spaces. Removing the spaces allowed me to select "Import first row as variable names" again.

            Comment


            • #7
              I also had this problem, and after some frustration I realised that the "cellrange" Stata was trying to import included a lot of empty columns. Specifying the correct cell range solved the problem.

              Comment


              • #8
                I have also had this problem - then realised that some of the variable names began with a number rather than a letter. So Stata would not 'import the first row as variable names' until these variable names were changed.

                Comment


                • #9
                  In my case, I had the same variable names. After changing the duplicate name, the problem was solved.
                  Last edited by Chaiyawat Suppaslip; 06 Mar 2023, 23:54.

                  Comment

                  Working...
                  X