Announcement

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

  • Convert spell into panel data

    Dear Stata users,
    I have the following dataset:

    I want to convert my dataset into monthly panel data (I am aware that some observations will be repeated). Could anyone explain me how should I code this? I know that there is a similar previous question (https://www.statalist.org/forums/for...ate-into-panel), but the code did not help in my case (I do not have experience with date variables). My dates start in 1983.
    Attached Files
    Last edited by Rui Tiago; 28 Jan 2020, 05:07.

  • #2
    That thread looks bang on in principle, so you need to expand here (pun intended).

    First off, an attachment is informative but nevertheless no use for copy and paste by people who might want to suggest code and (worse) we have to guess wildly whether we are seeing string variables or variables with value labels defined.

    Second, "did not help in my case" is a problem report that is hard to react to. Chiefly the difficulty is the first point again that we can have no precise idea how your dates are held.

    https://www.statalist.org/forums/help#stata explains both points at length and what to do instead.

    Comment


    • #3
      Dear Nick Cox,
      Sorry for not being so clear about the data. Here is an example created with dataex:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input long id byte(spellnr spelltyp) int(begin end)
      101 1 1 1 72
      102 1 10 1 72
      103 1 1 1 48
      201 1 6 1 300
      201 2 10 1 24
      end
      My variables are in numeric format.

      Comment


      • #4
        Thanks for the example. What I can suggest is that you use Stata's monthly dates rather than a scheme in which December 1982 is origin.

        That said, looking at the data more carefully makes it clear that spells can overlap so I can't be confident what you want next.

        Code:
        clear
        input long id byte(spellnr spelltyp) int(begin end)
        101 1 1 1 72
        102 1 10 1 72
        103 1 1 1 48
        201 1 6 1 300
        201 2 10 1 24
        end
        
        gen date1 = begin + ym(1982, 12) 
        gen date2 = end + ym(1982, 12) 
        format date? %tm 
        
        list 
        
            +-----------------------------------------------------------+
             |  id   spellnr   spelltyp   begin   end    date1     date2 |
             |-----------------------------------------------------------|
          1. | 101         1          1       1    72   1983m1   1988m12 |
          2. | 102         1         10       1    72   1983m1   1988m12 |
          3. | 103         1          1       1    48   1983m1   1986m12 |
          4. | 201         1          6       1   300   1983m1   2007m12 |
          5. | 201         2         10       1    24   1983m1   1984m12 |
             +-----------------------------------------------------------+
        
        .

        Comment


        • #5
          Dear Nick Cox,
          Thank you for your help. What I would like to have is, for example, for id 101:
          id date spelltyp
          101 1983m1 1
          101 1983m2 1
          ...
          101 1988m12 1
          I thought that Stata would not have problem with spells that can overlap and could create:
          id date spelltyp
          201 1983m1 6
          201 1983m2 6
          ...
          201 2007m12 6
          201 1983m1 10
          201 1983m2 10
          ...
          201 1984m12 10
          If it is not possible, I will only keep the spelltyp with a longer duration. I should have been more clear, sorry for that.

          Comment


          • #6
            OK. So now the thread cited in #1 should apply then.

            Comment

            Working...
            X