Announcement

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

  • Reshape long error

    Hi, I have an example of dataset following and there is an issue with reshaping the formant from wide to long.

    Code:
    clear
    input long(fips00 fips01 fips02 fips03 fips04 fips05 fips06 fips07 fips08 fips09 fips10 fips11 fips12 fips13 fips14 fips15 fips16 fips17 fips18 fips19) str3 fipschange long fipscounty
        . 48497 48497 48497 48497 48497     .     .     .     .     .     .     .     .     .     .     .     .     .     . "No " 48497
    48201 48201 48201 48201 48201 48201 48201 48201 48201 48201 48201 48201 48201 48201 48201 48201 48201 48201 48201 48201 "No " 48201
        . 48201 48201     .     .     .     .     .     .     .     .     .     .     .     .     .     .     .     .     . "No " 48201
        .     .     .     .     .     .     .     .     .     .     .     .     .     .     .     .     .     .     .     . "No " 48439
        . 48113 48113 48113 48113 48113 48113 48113 48113 48113 48113 48113 48113 48113 48113 48113 48113 48113 48113 48113 "No " 48113
    end

    The code I ran to reshape is

    Code:
    reshape long sic emp empc fips dnbrating paydexmax paydexmin sales salesc, i(id) j(year)
     (j = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 90 91 92 93 94 95 96 97 98 99)

    Then I have only fips00, fips01, ... fips09. The rest variables from fips10 to fips19 is not produced as it used to be. This problem is associated with other variables as well. I have one error message at the end of the screen "( is not a valid command name)" so I believe that something went wrong to identify variable names in the program. Any comment and feedback would be appreciated!

  • #2
    I would rename fipschange and fipscounty because they are all too likely to get mixed with fips??

    Also stubs like 00 to 19 are numeric to you and us, but are better explained to reshape via a string option.

    Then after the reshape you can go something like

    Code:
    gen year2 = real("20" + year) 
    drop year 
    rename year2 year

    Comment


    • #3
      Thanks for your prompt reply!
      I have tried to fix this issue following your suggestion but still same issue occurred. Variables starting the last two-digit from 10 to 99 were not generated.

      Code:
      rename fipschange changefips
      rename fipscounty countyfips 
      
      tostring sic* emp* empc* fips* dnbrating* paydexmax* paydexmin* sales* salesc*, replace
      
      gen id = _n
      
      reshape long sic emp empc fips dnbrating paydexmax paydexmin sales salesc, i(id) j(year)
      (j = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 90 91 92 93 94 95 96 97 98 99)

      Comment


      • #4
        Not what I said. I recommended a string option on reshape, not to use the tostring command.

        This works for me. You have more variables in your code than in your data example, but should just try extending the code accordingly.

        Code:
        clear
        input long(fips00 fips01 fips02 fips03 fips04 fips05 fips06 fips07 fips08 fips09 fips10 fips11 fips12 fips13 fips14 fips15 fips16 fips17 fips18 fips19) str3 fipschange long fipscounty
            . 48497 48497 48497 48497 48497     .     .     .     .     .     .     .     .     .     .     .     .     .     . "No " 48497
        48201 48201 48201 48201 48201 48201 48201 48201 48201 48201 48201 48201 48201 48201 48201 48201 48201 48201 48201 48201 "No " 48201
            . 48201 48201     .     .     .     .     .     .     .     .     .     .     .     .     .     .     .     .     . "No " 48201
            .     .     .     .     .     .     .     .     .     .     .     .     .     .     .     .     .     .     .     . "No " 48439
            . 48113 48113 48113 48113 48113 48113 48113 48113 48113 48113 48113 48113 48113 48113 48113 48113 48113 48113 48113 "No " 48113
        end
        
        rename (fipschange fipscounty) (change county)
        
        gen long id = _n 
        
        reshape long fips, i(id) j(year) string

        Comment


        • #5
          Maybe I did not state clearly what my variables are and that cause another problem.
          After running the reshape command from wide to long, number of variables transformed are 96 out of 222, which is still a problem.
          Following is the data example after reshaping and "_x"... "three" are misspecified due to the string command

          Code:
          clear
          input float id str10 year
          1 "00"        
          1 "01"        
          1 "02"        
          1 "03"        
          1 "04"        
          1 "05"        
          1 "06"        
          1 "07"        
          1 "08"        
          1 "09"        
          1 "10"        
          1 "11"        
          1 "12"        
          1 "13"        
          1 "14"        
          1 "15"        
          1 "16"        
          1 "17"        
          1 "18"        
          1 "19"        
          1 "_x"        
          1 "_y"        
          1 "eight"     
          1 "four"      
          1 "growth"    
          1 "growthpeer"
          1 "here"      
          1 "herec"     
          1 "six"       
          1 "three"     
          end

          Comment


          • #6
            It's the same problem. fips as a stub or prefix can't be used for both your fips?? and for other variables. You evidently have variables with names like fips_x fips_y and so forth.

            I don't think I can offer more help without an example that includes all variables. It doesn't much matter how many observations.

            Comment

            Working...
            X