Announcement

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

  • Error on reshaping data from wide to long

    I am trying to reshape county-wise GDP data from wide to long. Since the data is imported from Excel the column names are given as F,..,Z, and AA, .., AL

    forvalues i = F/Z{
    local j = 1990/2010
    ren `i' `j', force
    }

    this is what I am trying to do

    Click image for larger version

Name:	data.png
Views:	1
Size:	204.8 KB
ID:	1744864

  • #2
    Code:
    forvalues i = F/Z
    is quite wrong, so presumably that evokes your first error message (which you should have shown us).

    forvalues has one dedicated use, looping over regularly spaced integer sequences, and no more.

    Code:
    local j 1990/2010
    is itself correct (meaning legal) syntax but even if the loop had been entered as you perhaps intend

    Code:
    rename F 1990/2010, force 
    would make no sense to Stata as 1990/2010 is not a legal variable name and rename doesn't support a force option.

    What is going on here? Are you guessing at the syntax? Did you use some AI bot to produce syntax?


    Code:
    F G H I J K L M N O P Q R S T U V W X Y Z AA AB AC AD AE AF AG AH AI AJ AK AL
    is 33 variable names and

    Code:
    rename (F-AL) (whatever#) , addnumber(1990)
    will rename those variables to whatever1990 to whatever2022 where whatever should be replaced by whatever you want there.

    Then the reshape long should be straightforward. You will need to destring most of your variables sooner or later.








    Comment


    • #3
      How do I then reshape the data from wide to long?

      Comment

      Working...
      X