I've two cross-sectional datasets merging together. The data has variables about working from home pre-covid_19 ( wfh_pre) and during Covid-19 (wfh-post). Where are these variables is a dummy variable showing if an individual is working from home. I would like to calculate the maximum number (peak %) of people working from home within each occupation (jbsoc10_cc_agg), separately for the pre-COVID-19 and post-COVID-19 periods. For example, working from home in a Nurse occupation should have two columns, one for pre-covid-19 and the other for post_covid-19
I try with this code, but I'm not sure if this is what I'm looking for :
Could you help with that?
This is my sample data. I provided it separately to just show who is working from home pre/ post :
I try with this code, but I'm not sure if this is what I'm looking for :
Code:
* Collapse the data to get the total number of people working from home by occupation and year collapse (sum) wfh_pre wfh_post, by(jbsoc10_cc_agg ) ///*Create Temporary Files for Pre and Post COVID-19 Data/// * Save the collapsed data to a temporary file tempfile collapsed_datai save "collapsed_data", replace * Create and save pre-COVID-19 data use "collapsed_data", clear collapse (max) wfh_pre, by(jbsoc10_cc_agg) tempfile pre_covid_peak save "pre_covid_peak", replace * Create and save post-COVID-19 data use "collapsed_data", clear collapse (max) wfh_post, by(jbsoc10_cc_agg) tempfile post_covid_peak save "post_covid_peak", replace ///*Merge Pre and Post COVID-19 Data/// * Merge pre and post COVID-19 data use "pre_covid_peak", clear rename wfh_pre peak_wfh_pre merge 1:1 jbsoc10_cc_agg using "post_covid_peak" rename wfh_post peak_wfh_post drop _merge ///*Merge with the Original Dataset/// * Save the merged peak data to a temporary file tempfile combined_peak_wfh save "combined_peak_wfh", replace * Merge with the original dataset use "path_to_original_dataset.dta", clear merge m:1 jbsoc10_cc_agg using "`combined_peak_wfh'"
This is my sample data. I provided it separately to just show who is working from home pre/ post :
Code:
* Example generated by -dataex-. For more info, type help dataex clear input double pidp int jbsoc10_cc_agg float(tq wfh_post) 70414697 721 241 1 89358129 . 241 1 137259367 415 241 1 137330089 231 241 1 138099169 . 241 1 138519411 223 241 1 204395091 . 241 1 204791531 . 241 1 205104333 223 241 1 272014285 321 241 1 272124451 222 241 1 272148251 415 241 1 272269291 . 241 1 272291727 313 241 1 272328451 242 241 1 272401211 231 241 1 272401891 213 241 1 272408691 125 241 1 272465127 612 241 1 272533807 323 241 1 272541971 212 241 1 272588219 413 241 1 272709313 312 241 1 272971051 353 241 1 273113847 . 241 1 273143771 231 241 1 273459293 221 241 1 273729255 341 241 1 273787045 125 241 1 273864567 231 241 1 275361245 222 241 1 275957686 612 241 1 277059298 323 241 1 279072770 222 241 1 282098764 242 241 1 285908729 354 241 1 293213965 244 241 1 299462489 . 241 1 300324725 511 241 1 340182931 213 241 1 340212233 211 241 1 340274727 421 241 1 340303291 211 241 1 340304647 231 241 1 340341371 212 241 1 340540607 231 241 1 340556931 . 241 1 340568487 814 241 1 340631727 113 241 1 340727615 . 241 1 340727619 . 241 1 340899647 . 241 1 340958127 115 241 1 341117931 112 241 1 341126767 . 241 1 341404889 415 241 1 341709525 313 241 1 341709529 241 241 1 341800653 231 241 1 342484049 . 241 1 342554091 231 241 1 343941969 . 241 1 354157609 412 241 1 354273205 223 241 1 367660369 212 241 1 408017699 211 241 1 408031971 . 241 1 408120367 . 241 1 408306687 . 241 1 408348847 612 241 1 408666407 . 241 1 408975131 412 241 1 409115211 . 241 1 409208371 231 241 1 409306975 . 241 1 410520771 415 241 1 410564971 . 241 1 410836289 356 241 1 410910534 411 241 1 411714849 . 241 1 419553966 125 241 1 421648977 213 241 1 421657129 244 241 1 421855021 . 241 1 422141293 221 241 1 436324117 245 241 1 436331529 614 241 1 476322343 612 241 1 476499811 412 241 1 476532451 212 241 1 477104327 231 241 1 477104331 . 241 1 477143087 . 242 1 478384767 . 241 1 478443925 415 241 1 478643847 . 241 1 478775773 231 241 1 478894089 231 241 1 479637329 125 242 1 486968484 531 242 1 end format %tq tq label values jbsoc10_cc_agg b_jbsoc10_cc label def b_jbsoc10_cc 112 "Production Managers and Directors", modify label def b_jbsoc10_cc 113 "Functional Managers and Directors", modify label def b_jbsoc10_cc 115 "Financial Institution Managers and Directors", modify label def b_jbsoc10_cc 125 "Managers and Proprietors in Other Services", modify label def b_jbsoc10_cc 211 "Natural and Social Science Professionals", modify label def b_jbsoc10_cc 212 "Engineering Professionals", modify label def b_jbsoc10_cc 213 "Information Technology and Telecommunications Professionals", modify label def b_jbsoc10_cc 221 "Health Professionals", modify label def b_jbsoc10_cc 222 "Therapy Professionals", modify label def b_jbsoc10_cc 223 "Nursing and Midwifery Professionals", modify label def b_jbsoc10_cc 231 "Teaching and Educational Professionals", modify label def b_jbsoc10_cc 241 "Legal Professionals", modify label def b_jbsoc10_cc 242 "Business, Research and Administrative Professionals", modify label def b_jbsoc10_cc 244 "Welfare Professionals", modify label def b_jbsoc10_cc 245 "Librarians and Related Professionals", modify label def b_jbsoc10_cc 312 "Draughtspersons and Related Architectural Technicians", modify label def b_jbsoc10_cc 313 "Information Technology Technicians", modify label def b_jbsoc10_cc 321 "Health Associate Professionals", modify label def b_jbsoc10_cc 323 "Welfare and Housing Associate Professionals", modify label def b_jbsoc10_cc 341 "Artistic, Literary and Media Occupations", modify label def b_jbsoc10_cc 353 "Business, Finance and Related Associate Professionals", modify label def b_jbsoc10_cc 354 "Sales, Marketing and Related Associate Professionals", modify label def b_jbsoc10_cc 356 "Public Services and Other Associate Professionals", modify label def b_jbsoc10_cc 411 "Administrative Occupations: Government and Related Organisations", modify label def b_jbsoc10_cc 412 "Administrative Occupations: Finance", modify label def b_jbsoc10_cc 413 "Administrative Occupations: Records", modify label def b_jbsoc10_cc 415 "Other Administrative Occupations", modify label def b_jbsoc10_cc 421 "Secretarial and Related Occupations", modify label def b_jbsoc10_cc 511 "Agricultural and Related Trades", modify label def b_jbsoc10_cc 531 "Construction and Building Trades", modify label def b_jbsoc10_cc 612 "Childcare and Related Personal Services", modify label def b_jbsoc10_cc 614 "Caring Personal Services", modify label def b_jbsoc10_cc 721 "Customer Service Occupations", modify label def b_jbsoc10_cc 814 "Construction Operatives", modify
Code:
* Example generated by -dataex-. For more info, type help dataex clear input double pidp int jbsoc10_cc_agg float(tq wfh_pre) 22445 242 226 1 22445 242 233 1 280165 215 235 1 4794685 356 209 1 68011567 . 200 1 68011567 . 208 1 68011567 . 216 1 68011567 125 232 1 68035367 . 200 1 68041487 354 216 1 68044207 . 200 1 68044207 . 216 1 68044207 . 224 1 68060527 356 224 1 68060527 356 232 1 68111527 118 224 1 68112207 . 200 1 68112207 213 225 1 68120371 125 232 1 68122407 . 200 1 68122407 . 208 1 68136009 421 224 1 68150975 213 233 1 68155731 . 200 1 68155731 231 225 1 68163887 . 209 1 68180887 415 232 1 68180891 . 200 1 68180891 214 208 1 68180891 214 216 1 68180891 214 232 1 68195851 . 225 1 68213531 . 233 1 68216247 . 200 1 68216247 . 208 1 68216247 231 224 1 68216247 231 232 1 68216251 313 208 1 68216251 213 224 1 68216251 213 232 1 68288327 356 232 1 68293091 . 232 1 68293099 331 232 1 68293767 . 200 1 68295131 . 225 1 68297167 . 200 1 68329127 354 217 1 68329131 . 200 1 68333207 . 200 1 68333207 . 208 1 68333207 . 224 1 68333207 . 232 1 68338651 . 200 1 68338651 . 216 1 68340011 . 200 1 68340075 246 232 1 68364491 354 225 1 68395771 247 232 1 68423647 . 208 1 68435887 . 200 1 68435887 . 208 1 68438607 . 216 1 68453571 415 233 1 68501167 . 208 1 68501167 . 216 1 68501167 213 225 1 68501167 213 232 1 68501171 356 232 1 68535847 . 200 1 68539251 213 224 1 68545367 113 232 1 68546047 . 200 1 68546047 213 224 1 68550127 353 224 1 68565087 113 216 1 68567809 . 208 1 68569167 125 225 1 68569171 . 200 1 68569171 . 216 1 68580727 . 216 1 68580727 . 225 1 68615411 416 232 1 68643291 113 209 1 68646096 415 233 1 68693607 . 200 1 68708571 . 200 1 68718771 . 200 1 68718771 . 208 1 68718771 . 216 1 68731007 . 200 1 68735087 . 200 1 68735767 . 200 1 68740599 112 217 1 68740599 213 225 1 68755487 . 200 1 68756171 . 200 1 68773847 . 200 1 68774525 . 200 1 68775213 . 200 1 68785407 113 232 1 end format %tq tq label values jbsoc10_cc_agg b_jbsoc10_cc label def b_jbsoc10_cc 112 "Production Managers and Directors", modify label def b_jbsoc10_cc 113 "Functional Managers and Directors", modify label def b_jbsoc10_cc 118 "Health and Social Services Managers and Directors", modify label def b_jbsoc10_cc 125 "Managers and Proprietors in Other Services", modify label def b_jbsoc10_cc 213 "Information Technology and Telecommunications Professionals", modify label def b_jbsoc10_cc 214 "Conservation and Environment Professionals", modify label def b_jbsoc10_cc 215 "Research and Development Managers", modify label def b_jbsoc10_cc 231 "Teaching and Educational Professionals", modify label def b_jbsoc10_cc 242 "Business, Research and Administrative Professionals", modify label def b_jbsoc10_cc 246 "Quality and Regulatory Professionals", modify label def b_jbsoc10_cc 247 "Media Professionals", modify label def b_jbsoc10_cc 313 "Information Technology Technicians", modify label def b_jbsoc10_cc 331 "Protective Service Occupations", modify label def b_jbsoc10_cc 353 "Business, Finance and Related Associate Professionals", modify label def b_jbsoc10_cc 354 "Sales, Marketing and Related Associate Professionals", modify label def b_jbsoc10_cc 356 "Public Services and Other Associate Professionals", modify label def b_jbsoc10_cc 415 "Other Administrative Occupations", modify label def b_jbsoc10_cc 416 "Administrative Occupations: Office Managers and Supervisors", modify label def b_jbsoc10_cc 421 "Secretarial and Related Occupations", modify
Comment