Announcement

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

  • declare data to be panel data

    Dear Statalist,
    I want this data to be panel data:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int year str397 TITEL long(colors language)
    1894 "Erdbeerkuchen"        1 5
    1894 "Gedeckte Apfeltorte"  7 7
    1896 "Rabarbarkuchen"       3 6
    1890 "Blaubertorte"         2 3
    1892 "Himbeersorbet"        6 2
    1895 "Tiramisu"             5 4
    1892 "Avokadocreme"         1 5
    1892 "Apfelkuchen"          1 4
    1892 "Streuselkuchen"       3 6
    1891 "Stachelbeereis"       4 3
    1890 "Schokoladenkuchen"    7 3
    1880 "Banaenbrot"           7 7
    1884 "Pfannkuchen"          3 1
    1896 "Ananaskuchen"         8 5
    1889 "Eistorte"             2 1
    1897 "Baise"                9 5
       . "Linzer Torte"        10 6
       . "Bananensplit"         . 7
    end
    label values colours colours
    label def colours 1 "blau", modify
    label def colours 2 "gelb", modify
    label def colours 3 "grün", modify
    label def colours 4 "himmelblau", modify
    label def colours 5 "lila", modify
    label def colours 6 "orange", modify
    label def colours 7 "rosa", modify
    label def colours 8 "rot", modify
    label def colours 9 "schwarz", modify
    label def colours 10 "weiß", modify
    label values language language
    label def language 1 "Danish", modify
    label def language 2 "English", modify
    label def language 3 "French", modify
    label def language 4 "German", modify
    label def language 5 "Greek", modify
    label def language 6 "Italian", modify
    label def language 7 "Latin", modify

    I already tried:

    bysort language colours year : gen n_colours_year = _N
    xtset n_colours_year year

    and I got the error message:

    repeated time values within panel

    I would like to have a panel data set about colours and year, that contains the sum of TITELES per language per colour sorted by year.

    Thank you very much in advance!!!
    Best,
    Rike Lich

  • #2
    You asked a similar question on 1 August within https://www.statalist.org/forums/for...moving-average

    You can't convince tsset or xtset to define a panel based on identifier and time variable when there are repeated time values.

    But the underlying problem is what you need to address: it doesn't obviously make any sense to have a variable containing number of observations as a panel identifier.

    A panel structure in Stata is very tightly defined: a numeric identifier, distinct in each panel, and an integer time variable, and at most one observation for each (identifier, time). I can't see that you're even close to that structure.

    Comment


    • #3
      Dear Nick!

      Thank you very much for your remarks!
      I solved the problem:

      bysort colours year: egen nr_languages = total(languages)
      duplicates drop year colours, force
      xtset colours year

      Best,
      Rike Lich

      Comment

      Working...
      X