Skip to content

Instantly share code, notes, and snippets.

@dbose
Created February 27, 2016 10:34
Show Gist options
  • Save dbose/4bdadb91db6c007557d1 to your computer and use it in GitHub Desktop.
Save dbose/4bdadb91db6c007557d1 to your computer and use it in GitHub Desktop.
R processing script for US-CPS data as served by IPUMS
df$CLASSWKR_f <- factor(df$CLASSWKR,
levels=c(0,10,13,14,20,21,22,23,24,25,26,27,28,29,99),
labels=c("NIU",
"Self-employed",
"Self-employed, not incorporated",
"Self-employed, incorporated",
"Works for wages or salary",
"Wage/salary, private",
"Private, for profit",
"Private, nonprofit",
"Wage/salary, government",
"Federal government employee",
"Armed forces",
"State government employee",
"Local government employee",
"Unpaid family worker",
"Missing/Unknown"))
df$AGE_f <- factor(df$AGE)
df$RELATE_f <- factor(df$RELATE,
levels=c(101,201,301,303,501,701,901,1001,1113,1114,1115,1241,1242,1260,9100,9200,9900,9999),
labels=c("Head/householder",
"Spouse",
"Child",
"Stepchild",
"Parent",
"Sibling",
"Grandchild",
"Other relatives, n.s.",
"Partner/roommate",
"Unmarried partner",
"Housemate/roommate",
"Roomer/boarder/lodger",
"Foster children",
"Other nonrelatives",
"Armed forces, relationship unknown",
"Age under 14, relationship unknown",
"Relationship unknown",
"NIU"))
df$OFFPOV_f <- factor(df$OFFPOV,
levels = c(1,2,99),
labels = c("Below Poverty Line",
"Above Poverty Line",
"NIU"))
df$MARST_f <- factor(df$MARST,
levels = c(1,2,3,4,5,6,7,9),
labels = c("Married, spouse present",
"Married, spouse absent",
"Separated",
"Divorced",
"Widowed",
"Never married/single",
"Widowed or Divorced",
"NIU"))
labels <- c("N/A (not applicable)","Crop production","Animal production","Forestry except logging","Logging","Fishing, hunting, and trapping",
"Support activities for agriculture and forestry","Oil and gas extraction","Coal mining","Metal ore mining","Nonmetallic mineral mining and quarrying and not specified type of mining","Support activities for mining","Construction","Animal food, grain, and oilseed milling","Sugar and confectionery products","Fruit and vegetable preserving and specialty food manufacturing","Dairy product manufacturing","Animal slaughtering and processing","Retail bakeries","Bakeries, except retail","Seafood and other miscellaneous foods, n.e.c.","Not specified food industries","Beverage manufacturing","Tobacco manufacturing","Fiber, yarn, and thread mills","Fabric mills, except knitting","Textile and fabric finishing and coating mills","Carpet and rug mills","Textile product mills, except carpet and rug","Knitting mills, and apparel knitting mills","Cut and sew apparel manufacturing","Apparel accessories and other apparel manufacturing","Footwear manufacturing","Leather tanning and finishing and other allied products manufacturing","Sawmills and wood preservation","Veneer, plywood, and engineered wood products","Prefabricated wood buildings and mobile homes","Miscellaneous wood products","Pulp, paper, and paperboard mills","Paperboard containers and boxes","Miscellaneous paper and pulp products","Printing and related support activities","Petroleum refining","Miscellaneous petroleum and coal products","Resin, synthetic rubber and fibers, and filaments manufacturing","Agricultural chemical manufacturing","Pharmaceutical and medicine manufacturing","Paint, coating, and adhesives manufacturing","Soap, cleaning compound, and cosmetic manufacturing","Industrial and miscellaneous chemicals","Plastics product manufacturing","Tire manufacturing","Rubber product, except tire, manufacturing","Pottery, ceramics, and plumbing fixture manufacturing","Structural clay product manufacturing","Glass and glass product manufacturing","Cement, concrete, lime, and gypsum product manufacturing","Miscellaneous nonmetallic mineral product manufacturing","Iron and steel mills and steel product manufacturing","Aluminum production and processing","Nonferrous metal (except aluminum) production and processing","Foundries","Metal forgings and stampings","Cutlery and hand tool manufacturing","Structural metals, and boiler, tank, and shipping container manufacturing","Machine shops; turned product; screw, nut, and bolt manufacturing","Coating, engraving, heat treating and allied activities","Ordnance","Miscellaneous fabricated metal products manufacturing","Not specified metal industries","Agricultural implement manufacturing","Construction, and mining and oil and gas field machinery manufacturing","Commercial and service industry machinery manufacturing","Metalworking machinery manufacturing","Engines, turbines, and power transmission equipment manufacturing","Machinery manufacturing, n.e.c.","Computer and peripheral equipment manufacturing","Communications, and audio and video equipment manufacturing","Navigational, measuring, electromedical, and control instruments manufacturing","Electronic component and product manufacturing, n.e.c.","Household appliance manufacturing","Electrical lighting and electrical equipment manufacturing, and other electrical component manufacturing, n.e.c.","Motor vehicles and motor vehicle equipment manufacturing","Aircraft and parts manufacturing","Aerospace product and parts manufacturing","Railroad rolling stock manufacturing","Ship and boat building","Other transportation equipment manufacturing","Furniture and related product manufacturing","Medical equipment and supplies manufacturing","Sporting and athletic goods, and doll, toy and game manufacturing","Miscellaneous manufacturing, n.e.c.","Not specified manufacturing industries","Motor vehicles, parts and supplies, merchant wholesalers",
"Furniture and home furnishing, merchant wholesalers","Lumber and other construction materials, merchant wholesalers","Professional and commercial equipment and supplies, merchant wholesalers","Metals and minerals, except petroleum, merchant wholesalers","Electrical and electronic goods, merchant wholesalers","Hardware, plumbing and heating equipment, and supplies, merchant wholesalers","Machinery, equipment, and supplies, merchant wholesalers","Recyclable material, merchant wholesalers","Miscellaneous durable goods, merchant wholesalers","Paper and paper products, merchant wholesalers","Drugs, sundries, and chemical and allied products, merchant wholesalers","Apparel, fabrics, and notions, merchant wholesalers","Groceries and related products, merchant wholesalers","Farm product raw materials, merchant wholesalers","Petroleum and petroleum products, merchant wholesalers","Alcoholic beverages, merchant wholesalers","Farm supplies, merchant wholesalers","Miscellaneous nondurable goods, merchant wholesalers","Wholesale electronics markets, agents and brokers","Not specified wholesale trade","Automobile dealers","Other motor vehicle dealers","Auto parts, accessories, and tire stores","Furniture and home furnishings stores","Household appliance stores","Radio, TV, and computer stores","Building material and supplies dealers","Hardware stores","Lawn and garden equipment and supplies stores","Grocery stores","Specialty food stores","Beer, wine, and liquor stores","Pharmacies and drug stores","Health and personal care, except drug, stores","Gasoline stations","Clothing stores","Shoe stores","Jewelry, luggage, and leather goods stores","Sporting goods, camera, and hobby and toy stores","Sewing, needlework and piece goods stores","Music stores","Book stores and news dealers","Department stores and discount stores","Miscellaneous general merchandise stores","Retail florists","Office supplies and stationery stores","Used merchandise stores","Gift, novelty, and souvenir shops","Miscellaneous retail stores","Electronic shopping","Electronic auctions","Mail order houses","Vending machine operators","Fuel dealers","Other direct selling establishments","Not specified retail trade","Air transportation","Rail transportation","Water transportation","Truck transportation","Bus service and urban transit","Taxi and limousine service","Pipeline transportation","Scenic and sightseeing transportation","Services incidental to transportation","Postal Service","Couriers and messengers","Warehousing and storage","Electric power generation, transmission and distribution","Natural gas distribution","Electric and gas, and other combinations","Water, steam, air conditioning, and irrigation systems","Sewage treatment facilities","Not specified utilities","Newspaper publishers","Periodical, book, and directory publishers","Software publishers","Motion pictures and video industries","Sound recording industries","Radio and television broadcasting and cable subscription programming","Internet publishing and broadcasting and web search portals","Wired telecommunications carriers","Other telecommunication services","Data processing, hosting, and related services","Libraries and archives","Other information services","Banking and related activities","Savings institutions, including credit unions","Non-depository credit and related activities","Securities, commodities, funds, trusts, and other financial investments","Insurance carriers and related activities","Real estate","Automotive equipment rental and leasing","Video tape and disk rental","Other consumer goods rental","Commercial, industrial, and other intangible assets rental and leasing","Legal services","Accounting, tax preparation, bookkeeping and payroll services","Architectural, engineering, and related services","Specialized design services",
"Computer systems design and related services","Management, scientific and technical consulting services","Scientific research and development services","Advertising and related services","Veterinary services","Other professional, scientific and technical services","Management of companies and enterprises","Employment services","Business support services","Travel arrangements and reservation services","Investigation and security services","Services to buildings and dwellings","Landscaping services","Other administrative and other support services","Waste management and remediation services","Elementary and secondary schools","Colleges and universities, including junior colleges","Business, technical, and trade schools and training","Other schools and instruction, and educational support services","Offices of physicians","Offices of dentists","Office of chiropractors","Offices of optometrists","Offices of other health practitioners","Outpatient care centers","Home health care services","Other health care services","Hospitals","Nursing care facilities","Residential care facilities, without nursing","Individual and family services","Community food and housing, and emergency services","Vocational rehabilitation services","Child day care services","Independent artists, performing arts, spectator sports, and related industries","Museums, art galleries, historical sites, and similar institutions","Bowling centers","Other amusement, gambling, and recreation industries","Traveler accommodation","Recreational vehicle parks and camps, and rooming and boarding houses","Restaurants and other food services","Drinking places, alcoholic beverages","Automotive repair and maintenance","Car washes","Electronic and precision equipment repair and maintenance","Commercial and industrial machinery and equipment repair and maintenance","Personal and household goods repair and maintenance and footwear and leather goods repair","Barber shops","Beauty salons","Nail salons and other personal care services","Dry cleaning and laundry services","Funeral homes, and cemeteries and crematories","Other personal services","Religious organizations","Civic, social, advocacy organizations, and grantmaking and giving services","Labor unions","Business, professional, political, and similar organizations","Private households","Executive offices and legislative bodies","Public finance activities","Other general government and support","Justice, public order, and safety activities","Administration of human resource programs","Administration of environmental quality and housing programs","Administration of economic programs and space research",
"National security and international affairs","Armed Forces")
df$IND_f <- factor(df$IND,
levels = c(0000,0170,0180,0190,0270,0280,0290,0370,0380,0390,0470,
0490,0770,1070,1080,1090,1170,1180,1190,1270,1280,1290,
1370,1390,1470,1480,1490,1570,1590,1670,1680,1690,1770,
1790,3770,3780,3790,3875,1870,1880,1890,1990,2070,2090,
2170,2180,2190,2270,2280,2290,2370,2380,2390,2470,2480,
2490,2570,2590,2670,2680,2690,2770,2780,2790,2870,2880,
2890,2970,2980,2990,3070,3080,3095,3170,3180,3190,3365,
3370,3380,3390,3470,3490,3570,3580,3590,3670,3680,3690,
3895,3960,3970,3980,3990,4070,4080,4090,4170,4180,4195,
4265,4270,4280,4290,4370,4380,4390,4470,4480,4490,4560,
4570,4580,4585,4590,4670,4680,4690,4770,4780,4795,4870,
4880,4890,4970,4980,4990,5070,5080,5090,5170,5180,5190,
5275,5280,5295,5370,5380,5390,5470,5480,5490,5570,5580,
5590,5591,5592,5670,5680,5690,5790,6070,6080,6090,6170,
6180,6190,6270,6280,6290,6370,6380,6390,0570,0580,0590,
0670,0680,0690,6470,6480,6490,6570,6590,6670,6672,6680,
6690,6695,6770,6780,6870,6880,6890,6970,6990,7070,7080,
7170,7180,7190,7270,7280,7290,7370,7380,7390,7460,7470,
7480,7490,7570,7580,7590,7670,7680,7690,7770,7780,7790,
7860,7870,7880,7890,7970,7980,7990,8070,8080,8090,8170,
8180,8190,8270,8290,8370,8380,8390,8470,8560,8570,8580,
8590,8660,8670,8680,8690,8770,8780,8790,8870,8880,8970,
8980,8990,9070,9080,9090,9160,9170,9180,9190,9290,9370,
9380,9390,9470,9480,9490,9570,9590,9890),
labels = labels
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment