/************************************************************************************************************* This ado-file reads in CPS basic monthly files from before 1989. There are no dictionary files for these years, so I code myself. The record layouts have the form of (word, place). Each word has 6 characters, and the place gives the place in the word. For example, age is (17,1-2), meaning the position of age in the whole line is [16*6+1]-[16*6+2], or 97-98. 1976-1988 files and documentation: http://www.nber.org/cps. Before 1976: downloaded from ICPSR and saved in raw folder. ICPSR only has selected months, generally May, June, and October. Required: year0: first year to extract data year1: last year to extract data month0: first month of year month1: last month of year Options: savepath: location to save data set rawpath: location of raw pre-1976 files Example: to download CPS basic monthly files for 1986-1988 and save the resulting data sets in myfolder, type into command line load_cpsbasic_pre1989, year0(1986) year1(1988) month0(1) month1(12) savepath(myfolder) *************************************************************************************************************/ capture program drop load_cpsbasic_pre1989 program define load_cpsbasic_pre1989 version 12.0 syntax [anything], year0(integer) year1(integer) month0(integer) month1(integer) [rawpath(string) savepath(string)] #delimit; set more off; capture copy https://dl.dropboxusercontent.com/s/v5f4ob7bl10ffmo/gunzipfile.ado gunzipfile.ado, replace; /************************************************************************************************************* 1. Read in data *************************************************************************************************************/ forvalues yyyy=`year0'/`year1' {; local yy = substr(`"`yyyy'"',3,2); forvalues m = `month0'/`month1' {; local mon = string(mdy(`m',1,`yyyy'),`"%tdmon"'); clear all; global filename `mon'`yy'pub; local monthly = monthly("`mon'`yyyy'","MY"); /*Download and/or unzip data*/ if `yyyy'>=1976 {; /*These files downloaded on the fly from NBER*/ if `m'<10 {; global filename7688 cpsb`yy'0`m'; }; else {; global filename7688 cpsb`yy'`m'; }; qui copy http://nber.org/cps-basic/$filename7688.Z $filename7688.Z, replace; qui gunzipfile $filename7688.Z, replace; copy $filename7688 $filename.txt, replace; erase $filename7688.Z; erase $filename7688; local datfile $filename.txt; }; else if inlist(`"`mon'`yy'"',`""') {; /*These files downloaded on the fly from NBER*/ qui copy http://nber.org/cps/cps`mon'`yy'.zip `mon'`yy'.zip, replace; qui unzipfile `mon'`yy'.zip, replace; copy `mon's`yy' `mon'`yy'.txt, replace; erase `mon'`yy'.zip; erase `mon's`yy'; local datfile `mon'`yy'.txt; }; else if (`m'==10) | (`m'==5&`yyyy'>1968) | (`m'==6&inlist(`yy',71,73,74,75)) {; /*These files previously downloaded and saved in raw folder*/ qui unzipfile `"`rawpath'/$filename"', replace; local datfile $filename.txt; }; else {; /*Only have pre-1976 files for select months and years*/ continue; }; di "`mon'`yy'"; /*Infile. So far the variables I read are in the same positions in many years. I keep the layouts separate in case eventually there is a variable whose position changes*/ if inrange(`monthly',`=tm(1986m1)',`=tm(1988m12)') {; qui infix mis 2 double hhid 4-15 region 16 hg_st60 17-18 hhnum 48 line 541-542 a_hrs 50-51 a_whyabs 55 a_untype 65 str a_wkslk 66-67 a_whenlj1 71 a_whenlj 317 a_wantjb 74 a_age 97-98 marital 99 race 100 sex 101 a_hga 103-104 a_hgc 105 a_lfsr 109 double a_fnlwgt 121-132 a_emphrs 231-232 a_hrs2 296-297 a_rrp 347 a_maritl 350 a_uslhrs_uned 363-364 a_earnwgt 373-384 a_uslhrs 410-411 a_hrlywk 412 str mjocc 516-517 str mjind 518-519 str ind 524-526 str occu 527-529 using `datfile', clear; }; else if inrange(`monthly',`=tm(1985m7)',`=tm(1985m12)') {; qui infix mis 2 double hhid 4-15 region 16 hg_st60 17-18 hhnum 48 line 541-542 a_hrs 50-51 a_whyabs 55 a_untype 65 str a_wkslk 66-67 a_whenlj1 71 a_whenlj 317 a_wantjb 74 a_age 97-98 marital 99 race 100 sex 101 a_hga 103-104 a_hgc 105 a_lfsr 109 double a_fnlwgt 121-132 a_emphrs 231-232 a_uslhrs_uned 363-364 a_uslhrs 410-411 a_hrlywk 412 str mjocc 516-517 str mjind 518-519 str ind 524-526 str occu 527-529 using `datfile', clear; }; else if inrange(`monthly',`=tm(1984m1)',`=tm(1985m6)') {; qui infix mis 2 double hhid 4-15 region 16 hg_st60 17-18 hhnum 48 line 541-542 a_hrs 50-51 a_whyabs 55 a_untype 65 str a_wkslk 66-67 a_whenlj1 71 a_whenlj 317 a_wantjb 74 a_age 97-98 marital 99 race 100 sex 101 a_hga 103-104 a_hgc 105 a_lfsr 109 double a_fnlwgt 121-132 a_emphrs 231-232 a_uslhrs_uned 363-364 a_uslhrs 410-411 a_hrlywk 412 str mjocc 516-517 str mjind 518-519 str ind 524-526 str occu 527-529 using `datfile', clear; }; else if inrange(`monthly',`=tm(1983m1)',`=tm(1983m12)') {; qui infix mis 2 double hhid 4-15 region 16 hg_st60 17-18 hhnum 48 line 94-95 a_hrs 50-51 a_whyabs 55 a_untype 65 str a_wkslk 66-67 a_whenlj1 71 a_whenlj 317 a_wantjb 74 a_age 97-98 marital 99 race 100 sex 101 a_hga 103-104 a_hgc 105 a_lfsr 109 double a_fnlwgt 121-132 a_emphrs 231-232 a_uslhrs_uned 363-364 a_uslhrs 410-411 a_hrlywk 412 str mjocc 516-517 str mjind 518-519 str ind 524-526 str occu 527-529 using `datfile', clear; }; else if inrange(`monthly',`=tm(1982m1)',`=tm(1982m12)') {; qui infix mis 2 double hhid 4-15 region 16 hg_st60 17-18 hhnum 48 line 94-95 a_hrs 50-51 a_whyabs 55 a_untype 65 str a_wkslk 66-67 a_whenlj1 71 a_whenlj 317 a_wantjb 74 a_age 97-98 marital 99 race 100 sex 101 a_hga 103-104 a_hgc 105 a_lfsr 109 double a_fnlwgt 121-132 a_emphrs 231-232 a_uslhrs_uned 363-364 a_uslhrs 410-411 a_hrlywk 412 str ind 88-90 str occu 91-93 str mjind 215-216 using `datfile', clear; }; else if inrange(`monthly',`=tm(1977m4)',`=tm(1981m12)') {; qui infix mis 2 double hhid 4-15 region 16 hg_st60 17-18 hhnum 48 line 94-95 a_hrs 50-51 a_whyabs 55 a_untype 65 str a_wkslk 66-67 a_whenlj1 71 a_whenlj 317 a_wantjb 74 a_age 97-98 marital 99 race 100 sex 101 a_hga 103-104 a_hgc 105 a_lfsr 109 double a_fnlwgt 121-132 a_emphrs 231-232 str ind 88-90 str occu 91-93 str mjind 215-216 using `datfile', clear; }; else if inrange(`monthly',`=tm(1972m1)',`=tm(1977m3)') {; qui infix mis 2 double hhid 4-15 region 16 hg_st60 17-18 hhnum 48 line 94-95 a_hrs 50-51 a_whyabs 55 a_untype 65 str a_wkslk 66-67 a_whenlj1 71 a_wantjb 74 a_age 97-98 marital 99 race 100 sex 101 a_hga 103-104 a_hgc 105 a_lfsr 109 double a_fnlwgt 121-132 a_emphrs 231-232 str ind 88-90 str occu 91-93 str mjind 215-216 using `datfile', clear; }; else if inrange(`monthly',`=tm(1968m1)',`=tm(1971m12)') {; qui infix mis 2 double hhid 4-15 region 16 hg_st60 17-18 hhnum 48 line 94-95 a_hrs 50-51 a_whyabs 55 a_untype 65 str a_wkslk 66-67 a_whenlj1 71 a_wantjb 74 a_age 97-98 marital 99 race 100 sex 101 a_hga 103-104 a_hgc 105 a_lfsr 109 double a_fnlwgt 121-132 a_emphrs 231-232 a_hrlywk 390 str ind 88-90 str occu 91-93 str mjind_i 221-222 using `datfile', clear; }; /*Variable labels and value labels*/ qui destring a_wkslk, force replace; foreach var in ind mjind occ mjocc {; cap qui replace `var'="." if `var'=="---"; }; qui gen a_educ = a_hga-a_hgc+1; /*Codes educ as highest grade completed*/ label variable a_hga `"Highest grade attended"'; label variable a_hgc `"Grade completed"'; label variable a_educ `"Highest grade completed"'; label variable a_whenlj `"When did last work at a full-time job or business lasting 2 consecutive weeks"'; label variable a_whenlj1 `"When did last work at a full-time job or business lasting 2 consecutive weeks"'; label variable a_hrs `"Hours worked last week at all jobs"'; capture label variable a_uslhrs `"Usual hours worked per week"'; capture label variable a_uslhrs_uned `"Usual hours worked per week, unedited"'; capture label variable a_hrlywk `"Paid by hour"'; cap lab var a_rrp "Relationship to reference person"; cap lab var a_maritl "Marital status"; label variable a_wantjb `"Does ... want a regular job now?"'; label define a_wantjb 1 `"Yes"' 2 `"Maybe, it depends"' 3 `"No"' 4 `"Don't know"'; label define a_whenlj 1 `"In last 12 months"' 2 `"1-5 years"' 3 `"Before last 5 years"' 4 `"Never worked full-time 2 weeks or more"' 5 `"Never worked at all"'; label define a_whenlj1 1 `"In last 5 years"' 2 `"Before last 5 years"' 3 `"Never worked full-time 2 weeks or more"' 4 `"Never worked at all"'; label define sex 1 `"Male"' 2 `"Female"'; label define a_untype 1 "Lost job" 2 "Quit job" 3 "Left school" 4 "Wanted temporary work" 5 "Other"; label define a_lfsr 1 `"Employed, at work"' 2 `"Employed, absent from work"' 3 `"Unemployed"' 4 `"NILF, house"' 5 `"NILF, school"' 6 `"NILF, unable"' 7 `"NILF, other"'; label variable a_whyabs `"Why was ... absent from work last week?"'; label define a_whyabs 1 `"Own illness"' 2 `"On vacation"' 3 `"Bad weather"' 4 `"Labor dispute"' 5 `"New job to begin within 30 days"' 6 `"Temporary layoff (under 30 days)"' 7 `"Indefinite layoff (30 days or more)"' 8 `"Other"'; label define a_emphrs 0 `"Unemployed or NILF"' 1 `"With a job but not at work, illness"' 2 `"With a job but not at work, vacation"' 3 `"With a job but not at work, bad weather"' 4 `"With a job but not at work, labor dispute"' 5 `"With a job but not at work, other"' 6 `"1-4 hours"' 7 `"5-14 hours"' 8 `"15-21 hours"' 9 `"22-29 hours"' 10 `"30-34 hours"' 11 `"35-39 hours"' 12 `"40 hours"' 13 `"41-47 hours"' 14 `"48 hours"' 15 `"49-59 hours"' 16 `"60 or more hours"'; label define a_rrp 1 "Reference person with other relatives in household" 2 "Reference person without other relatives in household" 3 "Husband" 4 "Wife" 5 "Own child" 6 "Parent" 7 "Brother/sister" 8 "Other relative" 9 "Non-relative of reference person with own relatives in household" 10 "Non-relative of reference person without own relatives"; label define a_maritl 1 "Married, civilian spouse present" 2 "Married, AF spouse present" 3 "Married, spouse absent" 4 "Widowed" 5 "Divorced" 6 "Separated" 7 "Never married"; if `monthly'>=`=tm(1982m1)' {; label define a_hrlywk 1 `"Yes"' 2 `"No"'; }; else {; label define a_hrlywk 0 `"Yes"' 1 `"No"'; }; label define region 1 "Northeast" 2 "North Central" 3 "South" 4 "West"; #delimit; label define hg_st60 11 MAINE 12 "NEW HAMPSHIRE" 13 VERMONT 14 MASSACHUSETTS 15 "RHODE ISLAND" 16 CONNECTICUT 19 "OTHER NEW ENGLAND" 21 "NEW YORK" 22 "NEW JERSEY" 23 PENNSYLVANIA 31 OHIO 32 INDIANA 33 ILLINOIS 34 MICHIGAN 35 WISCONSIN 39 "OTHER EAST NORTH CENTRAL" 41 MINNESOTA 42 IOWA 43 MISSOURI 44 "NORTH DAKOTA" 45 "SOUTH DAKOTA" 46 NEBRASKA 47 KANSAS 49 "WEST NORTH CENTRAL" 51 DELAWARE 52 MARYLAND 53 "DISTRICT OF COLUMBIA" 54 VIRGINIA 55 "WEST VIRGINIA" 56 "NORTH CAROLINA" 57 "SOUTH CAROLINA" 58 GEORGIA 59 FLORIDA 61 KENTUCKY 62 TENNESSEE 63 ALABAMA 64 MISSISSIPPI 69 "OTHER EAST SOUTH CENTRAL" 71 ARKANSAS 72 LOUISIANA 73 OKLAHOMA 74 TEXAS 79 "OTHER WEST SOUTH CENTRAL" 81 MONTANA 82 IDAHO 83 WYOMING 84 COLORADO 85 "NEW MEXICO" 86 ARIZONA 87 UTAH 88 NEVADA 89 "MOUNTAIN" 91 WASHINGTON 92 OREGON 93 CALIFORNIA 94 ALASKA 95 HAWAII 99 "OTHER PACIFIC" ; if `monthly'