Announcement

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

  • Construct entry level national unemployment rate variable when individual first enters the labor market

    Dear Stata forum,

    I have the following variables in my unbalanced individual panel dataset below:

    id is the personal identifier, year is the survey year, yls is year left schooling, and enun is national unemployment rate.

    I would like to construct an entry level national unemployment rate for each individual when the person first enters the labor market. As I understand it, this variable should vary over individuals but not survey years.

    Basically, I would like to assign to each individual the entry national unemployment rate (enun) when the individual first enters the labor market so yls<=(survey) year.

    I hope I am making sense.

    I would highly appreciate your help.

    Best,
    Nico


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input long id float(year yls enun)
      987365 2010 2010 7.1
      987365 2011 2010 7.5
     1558565 2011 2009 7.5
     2270525 2016 2013 4.8
     2270525 2017 2013 4.3
     2270525 2018 2013 4.1
     2670365 2010 2009 7.1
     2670365 2011 2009 7.5
     3567965 2014 2010   6
     3916125 2019 2018 3.7
    68028575 2009 2012 6.6
    68028575 2010 2012 7.1
    68028575 2012 2012 7.6
    68028575 2013 2012 7.3
    68028575 2014 2012   6
    68028575 2015 2012 5.3
    68028575 2016 2012 4.8
    68028575 2017 2012 4.3
    68028575 2018 2012 4.1
    68028575 2019 2012 3.7
    68028575 2020 2012 4.4
    68028575 2021 2012 4.4
    68028575 2022 2012 3.7
    68029935 2013 2018 7.3
    68029935 2014 2018   6
    68029935 2015 2018 5.3
    68029935 2019 2018 3.7
    68059171 2009 2011 6.6
    68059171 2010 2011 7.1
    68059171 2011 2011 7.5
    68059171 2012 2011 7.6
    68059171 2013 2011 7.3
    68059171 2014 2011   6
    68059171 2015 2011 5.3
    68059171 2016 2011 4.8
    68059171 2017 2011 4.3
    68059171 2018 2011 4.1
    68060535 2022 2021   4
    68086375 2020 2019 4.4
    68091131 2013 2011 7.3
    68091131 2014 2011   6
    68091131 2015 2011 5.3
    68121059 2016 2020 4.8
    68121059 2017 2020 4.3
    68121059 2018 2020 4.1
    68121059 2019 2020 3.7
    68121059 2020 2020 4.4
    68121059 2021 2020 4.4
    68121059 2022 2020 3.7
    68125131 2009 2011 8.7
    68125131 2010 2011 8.8
    68125131 2011 2011 8.9
    68125131 2012 2011 8.6
    68125131 2013 2011 8.2
    68125131 2014 2011 6.6
    68125131 2015 2011 5.7
    68125131 2016 2011 5.2
    68125131 2017 2011 4.7
    68125131 2018 2011 4.3
    68125131 2019 2011 4.1
    68125131 2020 2011   5
    68125131 2021 2011 4.8
    68125131 2022 2011   4
    68132615 2012 2011 7.6
    68132615 2013 2011 7.3
    68132615 2014 2011   6
    68132615 2015 2011 5.3
    68132615 2016 2011 4.8
    68132615 2017 2011 4.3
    68132615 2018 2011 4.1
    68132615 2019 2011 3.7
    68132615 2020 2011 4.4
    68132615 2021 2011 4.4
    68132615 2022 2011 3.7
    68142139 2016 2015 5.2
    68142139 2017 2015 4.7
    68142139 2020 2015   5
    68142143 2020 2019   5
    68142143 2021 2019 4.8
    68155055 2009 2009 6.6
    68155055 2010 2009 7.1
    68155055 2011 2009 7.5
    68155055 2012 2009 7.6
    68155055 2013 2009 7.3
    68155055 2017 2009 4.3
    68155055 2018 2009 4.1
    68155055 2019 2009 3.7
    68155055 2020 2009 4.4
    68155055 2021 2009 4.4
    68155055 2022 2009 3.7
    68155059 2009 2010 6.6
    68155059 2010 2010 7.1
    68155059 2011 2010 7.5
    68155059 2012 2010 7.6
    68155059 2013 2010 7.3
    68155059 2014 2010   6
    68155059 2015 2010 5.3
    68155059 2016 2010 4.8
    68155059 2017 2010 4.3
    68155059 2018 2010 4.1
    end

  • #2
    To clarify, (survey) years should be as large as yls when entering the labor market and larger for subsequent years.

    Comment


    • #3
      Code:
      gen byte not_in_labor_market = (year < yls)
      by id (not_in_labor_market year), sort: gen wanted = enun[1]

      Comment


      • #4
        Hi Clyde,
        Thanks a lot for your reply.
        I think we are almost there, but not quite as I have not communicated my question fully.
        Your code makes sense, yet I need to have one more restriction. I can only have those `wanted' who graduate and are then observed in the same and subsequent survey years. For instance, if I have someone with yls in 1970 and is observed in 1994, the person is in the labor market, but for my purpose, I cannot have that individual in there.
        I would appreciate your help once again.

        Comment


        • #5
          I'm not sure I understand your additional restriction. Let me restate it in my own words: you wish to exclude from the data set any person for whom their year of leaving school comes before the first year in which they were surveyed. If that is correct:
          Code:
          by id (year), sort: drop if yls < year[1]

          Comment


          • #6
            Correct Clyde, thank you very much for your help.
            This is it now, thank you.

            Comment

            Working...
            X