I have a panel dataset with 37 counties and quarterly data for 13 years which includes the number of new jobs created by sector. I would like to sum each quarter for each county for each year in the data set and then create a new variable that divides each county's proportion of jobs by the overall total by sector. I think this is a two-step process (one to sum each job sector by year and one to sum each county by year) but have never run a loop in Stata before. I want to use the egen function but collapse as well (example:
collapse (sum) x1 x2, by(id date) so that I can retain the raw data but also these collapsed totals for each year. Apologies for the very basic question, I'm a bit of a novice with Stata when it comes to creating variables and using loops and searching the archives didn't help very much.
Here's a sample of the data:
Thanks in advance for your assistance.
collapse (sum) x1 x2, by(id date) so that I can retain the raw data but also these collapsed totals for each year. Apologies for the very basic question, I'm a bit of a novice with Stata when it comes to creating variables and using loops and searching the archives didn't help very much.
Here's a sample of the data:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str16 county int year byte quarter int(agriculturefore miningquarrying) "Acadia" 1998 1 178 542 "Acadia" 1998 2 193 539 "Acadia" 1998 3 206 533 "Acadia" 1998 4 231 489 "Acadia" 1999 1 164 216 "Acadia" 1999 2 194 198 "Acadia" 1999 3 213 413 "Acadia" 1999 4 261 409 "Acadia" 2000 1 150 497 "Acadia" 2000 2 188 485 "Acadia" 2000 3 196 499 "Acadia" 2000 4 274 501 "Acadia" 2001 1 154 521 "Acadia" 2001 2 178 536 "Acadia" 2001 3 165 462 end
Thanks in advance for your assistance.
Comment