Announcement

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

  • command xtset

    Hi I am working on a set of panel data and I want to tell stata that I am working on panel data by using the command xtset. I tried to use "xtset year code" but stata responded as this "string variables not allowed in varlist; code is a string variable".

    The company code I am using contains both number and letters. In this case, how can I proceed to tell stata with the command xtset? Should I destring variable code or generate a new variable to replace code? Can anyone offer me some advice? thank you!

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str30 name int year str6 code int sic double(cash ta) float size double(ebit capex mtb)
    "2 TRAVEL GROUP PLC"  2002 "26702E" 7329      .        .         .       .       .    .
    "365 MEDIA GROUP PLC" 2003 "257J33" 7999      .        .         .       .       .    .
    "3I GROUP PLC"        2010 "960438" 6282      .  7081000 14.800778  223900   11300 1.28
    "3I INFRASTRUCTURE"   2005 "51266Q" 6726      .        .         .       .       .    .
    "3M COMPANY"          2008 "143982" 3841 301000 14379000  11.48128 3085000 1115000    .
    end

  • #2
    Code:
    encode code,gen(code1)
    drop code
    rename code1 code
    xtset year code
    2B or not 2B, that's a question!

    Comment


    • #3

      I think that you firstly need to obtain a unique identifier from the string variable. There are many posts on the subject.
      Code:
       egen company_id = group(code) 
      Etc. Next, you should check the duplicates in the panel as follows:
      Code:
       duplicates tag company_id year, gen(dup)
      Code:
      ​​​​​​​ tab dup 
      Finally, you can set the panel:
      Code:
       xtset company_id year 
      ​​​​​​​
      Code:
       xtdes
      ​​​​​​​
      Code:
      ​​​​​​​ ssc install xtpattern 
      ​​​​​​​
      Code:
      ​​​​​​​​​​​​​​ xtpattern, gen(pattern) 
      ​​​​​​​
      Code:
      ​​​​​​​​​​​​​​ order name code company_id year pattern 

      Comment


      • #4
        Thank you guys!
        Problem solved!

        Comment

        Working...
        X