Announcement

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

  • Months of unemployment as a new variable

    Hey!

    I need to calculate the months of unemployment from the time period 2001 - 2012. This variable "months of unemployment" should show the sum of the total duration of unemployment in months of every person from 2001 - 2012.
    For example how many months a person was registered as unemployed in 2001, also in 2002, but then in 2003 the person was not registered as unemployed anymore.

    I have following variables:

    - pid: describes the personal identification number
    - syear: describes the survey years, I need the years from 2001-2012
    - unemployedprevious: describes if a person was registered as unemployed in t-1 (registered as unemployed in the previous year) - I only have this variable from t-1
    - unemployedpreviousinmonths: months from january to december (in the previous year), describes how many months a person was registered as unemployed in t-1 - I only have this variable from t-1

    Could anyone please help me to find the right command in stata to get the months of unemployment?

    Thank you very much.

    Regards
    Tina

  • #2
    Could you share a snippet of what your data looks like? I'm having a hard time following. (If it's confidential, feel free to make up a few fake cases.)

    Comment


    • #3
      Of course. I hope you can understand it now.
      Click image for larger version

Name:	Unbenannt.JPG
Views:	1
Size:	84.1 KB
ID:	1408882

      in the first command with the variable "arbeitslos_vorjahr" this describes if a person was registered as unemployed in the previous year, 32.633 observations for yes, during the time period 2001-2012
      in the second command with the variable "arbeitslos_vorjahrmonate" this describes the months from january to december (1-12) and how many persons were unemployed how many months during the time period from 2001 - 2012

      if I'm using this command:
      bysort pid: egen byte totarbeitslos=total(arbeitslos_vorjahrmonate) if arbeitslos_gemeldet ==1 & syear >2000 & syear <2013

      I get:
      Click image for larger version

Name:	Unbenannt1.JPG
Views:	1
Size:	65.9 KB
ID:	1408884

      here I get the number of months from 1 to 100, so people were from 1 months to 100 months registered as unemployed during the time period 2001-2012
      here I don't know if I'm using the years in the command correctly (syears) because the unemployed variables are always from the previous year (t-1)
      Click image for larger version

Name:	Unbenannt2.JPG
Views:	1
Size:	21.7 KB
ID:	1408885
      here I have less observations than before, does anyone know why this is the case here?
      regarding the mean, it would make sense that people are approximately 33.60 months unemployed during the time period from 2001-2012

      why do I have different number of observations?
      is the command used correctly??

      THANK YOU!
      Attached Files

      Comment


      • #4
        So, you are trying to get the total months of unemployment collected together per personal ID, yes?

        So arbeitslos_vorjahrmonate is...the total of months in the previous year? But you are looking at a 12-year period? So is it one record per year per person, like:

        pid syear arbeitslos_vorjahrmonate
        12345 2002 8
        12345 2003 12
        12345 2004 6
        67890 2001 11

        If that is the case, and you only want records from between 2001 and 2012 (which would really be 2000 to 2011 from what you're saying, right?):

        (make sure you save your raw dataset first, because this is going to lose information as you proceed):

        Code:
        drop if syear<2001
        drop if syear>2012
        collapse (sum) arbeitslos_vorjahrmonate, by(pid)
        Your data would then look like this:

        pid arbeitslos_vorjahrmonate
        12345 26
        67890 11


        Then, it would be easy enough to get the average, or the numbers that comprise the average. For example:

        gen people=1 **adds a column to help you count unique IDs**
        collapse (sum) people arbeitslos_vorjahrmonate

        people arbeitslos_vorjahrmonate
        2 37

        Is this what you are trying to get at?

        Comment


        • #5
          Thank you very much for your help! Yes, you are right.

          I dropped the years and used your command:
          Code:
          collapse (sum) arbeitslos_vorjahrmonate, by(pid)
          but I still don't get the right results because the problem is that I have to restrict the observations by using "if" .....
          and with your command I cannot restrict the result.

          Do you maybe know how to handle this? THANK YOU!

          Comment


          • #6
            a duplicate topic, also with replies, here: https://www.statalist.org/forums/for...sum-over-years
            Best regards,

            Marcos

            Comment


            • #7
              Remind me what you need to restrict? If it's the years, you can drop that before doing the collapse.

              Code:
              drop if syear<2001
              drop if syear>2012
              Then use that command.

              Comment

              Working...
              X