Announcement

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

  • Stata importing first row variables as letters

    Hi,

    As mentioned in my title (and in the screenshots below), when I try to import my file from excel (I need to use the reshape command) ticking the first row box does not change my first row to variables and they are simply coming out as letters. I have looked everywhere and cannot find a solution.

    Any help or guidance is much appreciated!
    Click image for larger version

Name:	Screenshot 2022-11-24 at 15.40.27.png
Views:	1
Size:	757.4 KB
ID:	1690799

  • #2
    You are showing, I think, two import excel images. Selecting "first row as variable names" is clearly a better idea than not selecting it. What is not clear is what the data look like in Stata afterwards, for which you need to show a data example.

    Please see https://www.statalist.org/forums/help#stata -- which explains how to give data examples (and how not to give them, namely as images that no-one can copy and paste usefully).

    Comment


    • #3
      It's because the variable names in the original Excel variable failed the format requirement to be a variable name in Stata.

      In Stata, variable names cannot start with Arabic number (0-9), cannot have space in between, and cannot contain special symbols (-~!@#$%^&*()[]{}<>?/).

      There are some automatic conversions built into Stata to help. For example, it's smart enough to remove the space between "Country" and "Name" and returned "CountryName". And I believe it also tried to help with correcting the name "1970 (FDI)" by removing the leading numbers and the parentheses.

      Unfortunately, it'd also result in another FDI for 1971 as well. That caused a double variable name conflict, and so Stata decided to just use the Excel column alphabet index.

      In short, this is not an error. Either you can change the names in the original Excel file (e.g. rename them to FDI1970, etc.) or do some renaming after it's imported into Stata.

      Comment


      • #4
        Ken Chui understood this much better than I did. What was meant was that the variable names were often emerging as single letters, which Ken saw immediately. I went in quite the wrong direction and was puzzled that the variables themselves (their values) looked fine to me.

        Comment

        Working...
        X