Announcement

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

  • Stata command for panel data percentages

    Dear stata users,

    I am assessing the effects of state dependence i.e. employment at time t-1 and migration on employment at time t. My panel dataset which consists of information on employment and migration looks like the one below. Could you assist on stata command that would give descriptive statistics for the following:

    XX% of those who were employed at t - 1 and were also employed at time t
    XX% of previously employed (i.e. at time t-1) who did not migrate and were unemployed at time t
    hhid Year employment migration
    0231 1999 1 1
    0231 2000 0 0
    0548 1999 0 1
    0548 2000 1 1
    …..
    Many thanks in advance.

  • #2
    This may start you in a useful direction.
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str4 hhid int year byte(employment migration)
    "0231" 1999 1 1
    "0231" 2000 0 0
    "0548" 1999 0 1
    "0548" 2000 1 1
    "9876" 1999 1 0
    "9876" 2000 1 1
    end
    destring hhid, generate(hhidn)
    xtset hhidn year
    generate e = employment==1 & !missing(F.year)
    generate e_e = employment==1 & F.employment==1
    generate e_me = employment==1 & F.employment==0 & F.migration==0
    list, sepby(hhid) abbreviate(12)
    tab e_e if e
    tab e_me if e
    Code:
    . list, sepby(hhid) abbreviate(12)
    
         +---------------------------------------------------------------+
         | hhid   hhidn   year   employment   migration   e   e_e   e_me |
         |---------------------------------------------------------------|
      1. | 0231     231   1999            1           1   1     0      1 |
      2. | 0231     231   2000            0           0   0     0      0 |
         |---------------------------------------------------------------|
      3. | 0548     548   1999            0           1   0     0      0 |
      4. | 0548     548   2000            1           1   0     0      0 |
         |---------------------------------------------------------------|
      5. | 9876    9876   1999            1           0   1     1      0 |
      6. | 9876    9876   2000            1           1   0     0      0 |
         +---------------------------------------------------------------+
    
    . tab e_e if e
    
            e_e |      Freq.     Percent        Cum.
    ------------+-----------------------------------
              0 |          1       50.00       50.00
              1 |          1       50.00      100.00
    ------------+-----------------------------------
          Total |          2      100.00
    
    . tab e_me if e
    
           e_me |      Freq.     Percent        Cum.
    ------------+-----------------------------------
              0 |          1       50.00       50.00
              1 |          1       50.00      100.00
    ------------+-----------------------------------
          Total |          2      100.00

    Comment


    • #3
      Also, if you -destring- your hhid variable, you can -xtset hhid year-, which will enable you to use the -xttrans- command. -help xttrans- explains.

      In the future, when showing data examples, please use the -dataex- command to do so. If you are running version 15.1 or a fully updated version 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.



      When asking for help with code, always show example data. When showing example data, always use -dataex-.

      Comment


      • #4
        Many thanks for the codes and guidance on -dataex-. One quick question why did you use the forward code (F.) rathern than the lag one (L.)?

        Comment


        • #5
          why did you use the forward code (F.) rather than the lag one (L.)?
          Because the questions asked are, essentially, "for people employed in 1999, what fraction of them were ... in 2000". It's more natural to attach the outcomes (what happened in the 2000) to the observation that defines the qualifying condition (employed in 1999) than it is the other way around.

          And for a concrete example, while in your example there appear to be four possible outcomes in the next year (employed/unemployed x migrated/stayed) in any realistic setting there is a fifth outcome - missing from the data - perhaps they left the area where the survey is being taken, perhaps they were no longer able, or refused, to complete the survey in the next year. You will want to know the fraction of people employed in 1999 for whom you do not know their outcome, but using L. notation there will be no observation to which the information can be attached.

          Comment


          • #6
            Many thanks for the guidance.

            Comment

            Working...
            X