-------------
      name:  <unnamed>
       log:  Y:\projects\ERC_corrode\team\Pilar\filecreation\bhps\uspells_bhps_check.smcl
  log type:  smcl
 opened on:  30 Jun 2016, 10:16:49

.
.
. /***
>         CORRODE // UNEMPLOYMENT SPELLS CHECK
>         v0.1 28/6/16 pgp
> ***/
.
. ***
. *** PURPOSE:
. *** Check that all individuals R as unemployed/employed who changed since last year
. *** have a jobhist record
. ***
.
. ***
. ***
. ***
. ***
.
.
. ********************************************************************************
. ***     MERGING FILES FROM MULTIPLE WAVES
. ********************************************************************************
.
. *** job history
. clear

. local year=1991

. foreach w in a b c d e f g h i j k l m n o p q r {
  2.         qui {
  3. use "${in}\`w'jobhist"
  4. replace `w'jhbgm=. if inlist(`w'jhbgm,-9,-7,-1)
  5. replace `w'jhbgy4=. if inlist(`w'jhbgy4,-9,-7,-1)
  6. replace `w'jhendm=. if inlist(`w'jhendm,-9,-7,-1)
  7. replace `w'jhendy4=. if inlist(`w'jhendy4,-9,-7,-1)
  8. gen `w'sps=ym(`w'jhbgy4, `w'jhbgm) // start of spell //
  9. gen `w'spe=ym(`w'jhendy4, `w'jhendm) // end of spell //
 10. format `w'sps `w'spe %tm
 11. gen `w'edur = `w'spe - `w'sps if `w'jhstat<3   // length of employment spell //
 12. gen `w'udur = `w'spe - `w'sps if `w'jhstat==3  // lenght of unemployment spell //
 13. by pid, sort: egen `w'tudur = sum(`w'udur)  // unemployed months sum by person //
 14. by pid, sort: egen `w'tedur = sum(`w'edur)  // unemployed months sum by person //
 15. rename pid xpid
 16. rename `w'* *
 17. rename xpid pid
 18. keep pid udur tudur edur tedur sps spe jspno jhstat jhsoc jhisco ///
>         jhsemp jhboss jhsect jhmngr jhsize jhgpay jhgpayi jhnpay jhnpayi
 19. destring jhisco, replace force //puts a few that have invalid codes to missing
 20.         }
 21. gen wave=`year'
 22. local ++year
 23. tempfile jobhist_`w'
 24. save `jobhist_`w''
 25.  }
file C:\Users\gonalons\AppData\Local\Temp\ST_0a000001.tmp saved
file C:\Users\gonalons\AppData\Local\Temp\ST_0a000002.tmp saved
file C:\Users\gonalons\AppData\Local\Temp\ST_0a000003.tmp saved
file C:\Users\gonalons\AppData\Local\Temp\ST_0a000004.tmp saved
file C:\Users\gonalons\AppData\Local\Temp\ST_0a000005.tmp saved
file C:\Users\gonalons\AppData\Local\Temp\ST_0a000006.tmp saved
file C:\Users\gonalons\AppData\Local\Temp\ST_0a000007.tmp saved
file C:\Users\gonalons\AppData\Local\Temp\ST_0a000008.tmp saved
file C:\Users\gonalons\AppData\Local\Temp\ST_0a000009.tmp saved
file C:\Users\gonalons\AppData\Local\Temp\ST_0a00000a.tmp saved
file C:\Users\gonalons\AppData\Local\Temp\ST_0a00000b.tmp saved
file C:\Users\gonalons\AppData\Local\Temp\ST_0a00000c.tmp saved
file C:\Users\gonalons\AppData\Local\Temp\ST_0a00000d.tmp saved
file C:\Users\gonalons\AppData\Local\Temp\ST_0a00000e.tmp saved
file C:\Users\gonalons\AppData\Local\Temp\ST_0a00000f.tmp saved
file C:\Users\gonalons\AppData\Local\Temp\ST_0a00000g.tmp saved
file C:\Users\gonalons\AppData\Local\Temp\ST_0a00000h.tmp saved
file C:\Users\gonalons\AppData\Local\Temp\ST_0a00000i.tmp saved

.
. use `jobhist_a'

. foreach w in b c d e f g h i j k l m n o p q r {
  2. append using `jobhist_`w''
  3. }

.
. tempfile jobhist_long

. save `jobhist_long'
file C:\Users\gonalons\AppData\Local\Temp\ST_0a00000j.tmp saved

.
. *** individual file
. clear

. local year=2002

. foreach w in l m n o p q r{
  2. qui {
  3. use pid `w'hid `w'doi* `w'sex `w'doby `w'mlstat `w'ivstat2 ///intv month and basic demographic
> `w'school `w'qfedhi `w'isced ///education
> `w'jbhas `w'jboff `w'jbterm* `w'jbsoc `w'jbsic* `w'jbsemp `w'jbmngr `w'jbsect `w'jbsize `w'jbhrs ///current job
> `w'jbbgm `w'jbbgy* `w'jbbgly `w'jbstat `w'jbstatl `w'jbstatt `w'jbft `w'cjsbgm `w'cjsbgy `w'cjsten `w'jlid /// dates current job/emp status
> `w'payg `w'payn `w'paygu `w'paynu `w'fimnl `w'fiyrl ///pay
> `w'njbwks `w'njuwks `w'njiwks `w'njbsp `w'njusp `w'njisp ///spells derived variables
>  using "${in}\`w'indresp"
  4.  rename pid xpid
  5.  rename `w'* *
  6.  rename xpid pid
  7.  gen wave=`year'
  8.  local++year
  9.  tempfile indresp_`w'
 10.  save `indresp_`w''
 11.  }
 12.  }

.
. use `indresp_l'

. foreach w in m n o p q r {
  2. append using `indresp_`w''
  3. }

.
.         *changed employment status since September LY
.         gen idate = mdy(doim,doid,doiy4)

.         gen stly = mdy(9,1,doiy4-1)

.         format idate stly %d

.         gen tstly = idate - stly

.         gen chstly = cond(cjsten>0 & cjsten<=tstly, 1,  ///
>                                  cond(cjsten>0 & cjsten>tstly, 0, .))
(8,910 missing values generated)

.
.                 *check
.                 list pid idate jbstat cjsten stly tstly chstly in 1/30

     +-------------------------------------------------------------------------+
     |      pid       idate     jbstat     cjsten        stly   tstly   chstly |
     +-------------------------------------------------------------------------+
  1. | 10014578   29oct2002    retired      15711   01sep2001     423        0 |
  2. | 10014608   29oct2002    retired       1308   01sep2001     423        0 |
  3. | 10016813   16dec2002   employed   proxy an   01sep2001     471        . |
  4. | 10016872   16dec2002   employed       1690   01sep2001     471        0 |
  5. | 10017933   02oct2002   employed       1888   01sep2001     396        0 |
     +-------------------------------------------------------------------------+
  6. | 10017992   13nov2002   employed         73   01sep2001     438        1 |
  7. | 90001451   16dec2002    retired       7473   01sep2001     471        0 |
  8. | 10023526   25sep2002   employed       5229   01sep2001     389        0 |
  9. | 10048219   02dec2002   family c   proxy an   01sep2001     457        . |
 10. | 10049304   06mar2003   employed       1709   01sep2002     186        0 |
     +-------------------------------------------------------------------------+
 11. | 10049339   06mar2003   self-emp       4266   01sep2002     186        0 |
 12. | 10055266   01oct2002   employed        330   01sep2001     395        1 |
 13. | 10062351   26sep2002   self-emp       1183   01sep2001     390        0 |
 14. | 10062386   26sep2002      other         87   01sep2001     390        1 |
 15. | 10067213   16sep2002    missing   proxy an   01sep2001     380        . |
     +-------------------------------------------------------------------------+
 16. | 10067248   16sep2002   employed       4582   01sep2001     380        0 |
 17. | 10076166   09sep2002    retired      10297   01sep2001     373        0 |
 18. | 10078401   07oct2002    retired       2532   01sep2001     401        0 |
 19. | 10079556   31oct2002   self-emp       2313   01sep2001     425        0 |
 20. | 10079688   31oct2002   employed   proxy an   01sep2001     425        . |
     +-------------------------------------------------------------------------+
 21. | 10081798   09sep2002    retired       7375   01sep2001     373        0 |
 22. | 10087486   23nov2002   employed        369   01sep2001     448        1 |
 23. | 10094083   14sep2002   employed       4731   01sep2001     378        0 |
 24. | 10094113   14sep2002   employed       4001   01sep2001     378        0 |
 25. | 10094148   14sep2002   employed         47   01sep2001     378        1 |
     +-------------------------------------------------------------------------+
 26. | 10094172   24sep2002   ft studt        511   01sep2001     388        0 |
 27. | 93537891   14sep2002   employed        197   01sep2001     378        1 |
 28. | 10101942   05oct2002    retired       7186   01sep2001     399        0 |
 29. | 10101977   05oct2002   employed        396   01sep2001     399        1 |
 30. | 10103031   24sep2002   employed        235   01sep2001     388        1 |
     +-------------------------------------------------------------------------+

.                 //all chstly = 1 should have jobhist entry
.
.         *drop proxy respondents
.         drop if ivstat2==-7
(4,441 observations deleted)

.
. merge 1:m pid wave using `jobhist_long', keep(master matched)

    Result                           # of obs.
    -----------------------------------------
    not matched                        83,785
        from master                    83,785  (_merge==1)
        from using                          0  (_merge==2)

    matched                            27,834  (_merge==3)
    -----------------------------------------

.
.         *check matched by chstly
.         tab _merge chstly, miss

                      |              chstly
               _merge |         0          1          . |     Total
----------------------+---------------------------------+----------
      master only (1) |    77,035      2,624      4,126 |    83,785
          matched (3) |     1,171     26,175        488 |    27,834
----------------------+---------------------------------+----------
                Total |    78,206     28,799      4,614 |   111,619


.
. gen age = cond(doby>0, floor(doiy4 - doby), .)
(7 missing values generated)

.
.         *check, IT IS MOSTLY STUDENTS
.         tab age _merge if chstly==1, miss

           |        _merge
       age | master on  matched ( |     Total
-----------+----------------------+----------
        16 |       336        569 |       905
        17 |       348        945 |     1,293
        18 |       204      1,131 |     1,335
        19 |       144      1,224 |     1,368
        20 |       160      1,005 |     1,165
        21 |        96        946 |     1,042
        22 |        73      1,071 |     1,144
        23 |        56      1,040 |     1,096
        24 |        58        852 |       910
        25 |        44        841 |       885
        26 |        50        753 |       803
        27 |        39        722 |       761
        28 |        37        687 |       724
        29 |        47        653 |       700
        30 |        37        571 |       608
        31 |        33        621 |       654
        32 |        44        559 |       603
        33 |        31        551 |       582
        34 |        33        537 |       570
        35 |        36        633 |       669
        36 |        51        510 |       561
        37 |        37        575 |       612
        38 |        28        469 |       497
        39 |        40        521 |       561
        40 |        30        527 |       557
        41 |        35        526 |       561
        42 |        32        444 |       476
        43 |        37        469 |       506
        44 |        30        375 |       405
        45 |        29        389 |       418
        46 |        18        431 |       449
        47 |        24        361 |       385
        48 |        14        364 |       378
        49 |        20        315 |       335
        50 |        21        323 |       344
        51 |        20        309 |       329
        52 |        27        248 |       275
        53 |        16        245 |       261
        54 |        11        251 |       262
        55 |        13        251 |       264
        56 |        19        295 |       314
        57 |        12        244 |       256
        58 |        15        222 |       237
        59 |        13        198 |       211
        60 |        16        302 |       318
        61 |        26        189 |       215
        62 |         9        158 |       167
        63 |        16        125 |       141
        64 |        12        104 |       116
        65 |         6        186 |       192
        66 |        19        107 |       126
        67 |         3         49 |        52
        68 |         1         35 |        36
        69 |         2         32 |        34
        70 |         2         31 |        33
        71 |         4         17 |        21
        72 |         1          7 |         8
        73 |         1          9 |        10
        74 |         1         13 |        14
        75 |         2         14 |        16
        76 |         0          6 |         6
        77 |         0          1 |         1
        79 |         1          2 |         3
        80 |         0          3 |         3
        81 |         0          3 |         3
        82 |         1          2 |         3
        83 |         1          1 |         2
        85 |         0          5 |         5
        86 |         1          0 |         1
        87 |         1          0 |         1
        93 |         0          1 |         1
-----------+----------------------+----------
     Total |     2,624     26,175 |    28,799


.
.
. log close
      name:  <unnamed>
       log:  Y:\projects\ERC_corrode\team\Pilar\filecreation\bhps\uspells_bhps_check.smcl
  log type:  smcl
 closed on:  30 Jun 2016, 10:16:50
-------------