Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Grouping Data by year and Gender

    Hi,

    I have the following data for years 2012-2016 for males and females in this dataset. The v6, v7, v8 go all the way to 100 and tell us the number of people of each age. I want to add the values for each local authority by gender, and then total the numbers into age bands 1-10, 11-20 ect... so that I end up with the total number of people in each age band by local authority level.

    Any help is greatly appreciated!

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int year str7 gender str9 code str36 name str7(v6 v7 v8)
    2012 "Female " "E92000001" "ENGLAND"                         "339,662" "333,659" "329,489"
    2012 "Female " "E12000001" "NORTH EAST"                      "14,909"  "14,996"  "14,791" 
    2012 "Female " "E06000047" "County Durham"                   "2,755"   "2,913"   "2,877"  
    2012 "Female " "E06000005" "Darlington"                      "661"     "629"     "651"    
    2012 "Female " "E06000001" "Hartlepool"                      "557"     "559"     "575"    
    2012 "Female " "E06000002" "Middlesbrough"                   "983"     "1,039"   "925"    
    2012 "Female " "E06000057" "Northumberland"                  "1,507"   "1,520"   "1,569"  
    2012 "Female " "E06000003" "Redcar and Cleveland"            "755"     "798"     "750"    
    2012 "Female " "E06000004" "Stockton-on-Tees"                "1,245"   "1,223"   "1,225"  
    2012 "Female " "E11000007" "Tyne and Wear (Met County)"      "6,446"   "6,315"   "6,219"  
    2012 "Female " "E08000037" "Gateshead"                       "1,134"   "1,206"   "1,117"  
    2012 "Female " "E08000021" "Newcastle upon Tyne"             "1,657"   "1,695"   "1,663"  
    2012 "Female " "E08000022" "North Tyneside"                  "1,172"   "1,149"   "1,144"  
    2012 "Female " "E08000023" "South Tyneside"                  "846"     "790"     "807"    
    2012 "Female " "E08000024" "Sunderland"                      "1,637"   "1,475"   "1,488"  
    2012 "Female " "E12000002" "NORTH WEST"                      "43,919"  "43,373"  "42,508" 
    2012 "Female " "E06000008" "Blackburn with Darwen"           "1,170"   "1,046"   "1,094"  
    2012 "Female " "E06000009" "Blackpool"                       "932"     "830"     "810"    
    2012 "Female " "E06000049" "Cheshire East"                   "1,991"   "2,091"   "1,858"  
    2012 "Female " "E06000050" "Cheshire West and Chester"       "1,814"   "1,795"   "1,800"  
    2012 "Female " "E06000006" "Halton"                          "762"     "807"     "910"    
    2012 "Female " "E06000007" "Warrington"                      "1,195"   "1,294"   "1,166"  
    2012 "Female " "E10000006" "Cumbria"                         "2,527"   "2,524"   "2,453"  
    2012 "Female " "E07000026" "Allerdale"                       "480"     "523"     "510"    
    2012 "Female " "E07000027" "Barrow-in-Furness"               "386"     "366"     "330"    
    2012 "Female " "E07000028" "Carlisle"                        "656"     "627"     "586"    
    2012 "Female " "E07000029" "Copeland"                        "373"     "353"     "366"    
    2012 "Female " "E07000030" "Eden"                            "187"     "222"     "237"    
    2012 "Female " "E07000031" "South Lakeland"                  "445"     "433"     "424"    
    2012 "Female " "E11000001" "Greater Manchester (Met County)" "18,691"  "18,381"  "17,932" 
    2012 "Female " "E08000001" "Bolton"                          "2,003"   "1,957"   "1,920"  
    2012 "Female " "E08000002" "Bury"                            "1,244"   "1,277"   "1,167"  
    2012 "Female " "E08000003" "Manchester"                      "4,081"   "3,705"   "3,625"  
    2012 "Female " "E08000004" "Oldham"                          "1,648"   "1,642"   "1,650"  
    2012 "Female " "E08000005" "Rochdale"                        "1,461"   "1,484"   "1,429"  
    2012 "Female " "E08000006" "Salford"                         "1,709"   "1,750"   "1,579"  
    2012 "Female " "E08000007" "Stockport"                       "1,723"   "1,710"   "1,688"  
    2012 "Female " "E08000008" "Tameside"                        "1,518"   "1,485"   "1,498"  
    2012 "Female " "E08000009" "Trafford"                        "1,382"   "1,472"   "1,469"  
    2012 "Female " "E08000010" "Wigan"                           "1,922"   "1,899"   "1,907"  
    2012 "Female " "E10000017" "Lancashire"                      "6,529"   "6,719"   "6,738"  
    2012 "Female " "E07000117" "Burnley"                         "602"     "551"     "597"    
    2012 "Female " "E07000118" "Chorley"                         "612"     "649"     "634"    
    2012 "Female " "E07000119" "Fylde"                           "294"     "414"     "370"    
    2012 "Female " "E07000120" "Hyndburn"                        "539"     "517"     "518"    
    2012 "Female " "E07000121" "Lancaster"                       "775"     "779"     "688"    
    2012 "Female " "E07000122" "Pendle"                          "616"     "632"     "623"    
    2012 "Female " "E07000123" "Preston"                         "876"     "888"     "952"    
    2012 "Female " "E07000124" "Ribble Valley"                   "225"     "246"     "288"    
    2012 "Female " "E07000125" "Rossendale"                      "428"     "435"     "427"    
    2012 "Female " "E07000126" "South Ribble"                    "568"     "626"     "602"    
    2012 "Female " "E07000127" "West Lancashire"                 "544"     "534"     "573"    
    2012 "Female " "E07000128" "Wyre"                            "450"     "448"     "466"    
    2012 "Female " "E11000002" "Merseyside (Met County)"         "8,308"   "7,886"   "7,747"  
    2012 "Female " "E08000011" "Knowsley"                        "922"     "954"     "867"    
    2012 "Female " "E08000012" "Liverpool"                       "3,009"   "2,641"   "2,536"  
    2012 "Female " "E08000014" "Sefton"                          "1,386"   "1,439"   "1,441"  
    2012 "Female " "E08000013" "St. Helens"                      "1,092"   "1,021"   "1,070"  
    2012 "Female " "E08000015" "Wirral"                          "1,899"   "1,831"   "1,833"  
    2012 "Female " "E12000003" "YORKSHIRE AND THE HUMBER"        "33,314"  "32,361"  "32,652" 
    2012 "Female " "E06000011" "East Riding of Yorkshire"        "1,463"   "1,556"   "1,649"  
    2012 "Female " "E06000010" "Kingston upon Hull, City of"     "1,883"   "1,734"   "1,713"  
    2012 "Female " "E06000012" "North East Lincolnshire"         "1,054"   "960"     "1,048"  
    2012 "Female " "E06000013" "North Lincolnshire"              "944"     "1,019"   "975"    
    2012 "Female " "E06000014" "York"                            "1,051"   "1,031"   "1,071"  
    2012 "Female " "E10000023" "North Yorkshire"                 "3,049"   "3,023"   "3,048"  
    2012 "Female " "E07000163" "Craven"                          "267"     "240"     "255"    
    2012 "Female " "E07000164" "Hambleton"                       "452"     "423"     "437"    
    2012 "Female " "E07000165" "Harrogate"                       "797"     "843"     "848"    
    2012 "Female " "E07000166" "Richmondshire"                   "302"     "310"     "258"    
    2012 "Female " "E07000167" "Ryedale"                         "201"     "241"     "249"    
    2012 "Female " "E07000168" "Scarborough"                     "566"     "513"     "525"    
    2012 "Female " "E07000169" "Selby"                           "464"     "453"     "476"    
    2012 "Female " "E11000003" "South Yorkshire (Met County)"    "8,316"   "8,009"   "8,237"  
    2012 "Female " "E08000016" "Barnsley"                        "1,480"   "1,374"   "1,405"  
    2012 "Female " "E08000017" "Doncaster"                       "1,832"   "1,872"   "1,906"  
    2012 "Female " "E08000018" "Rotherham"                       "1,548"   "1,522"   "1,567"  
    2012 "Female " "E08000019" "Sheffield"                       "3,456"   "3,241"   "3,359"  
    2012 "Female " "E11000006" "West Yorkshire (Met County)"     "15,554"  "15,029"  "14,911" 
    2012 "Female " "E08000032" "Bradford"                        "4,140"   "3,994"   "4,036"  
    2012 "Female " "E08000033" "Calderdale"                      "1,290"   "1,259"   "1,304"  
    2012 "Female " "E08000034" "Kirklees"                        "2,942"   "2,926"   "2,746"  
    2012 "Female " "E08000035" "Leeds"                           "5,107"   "4,896"   "4,898"  
    2012 "Female " "E08000036" "Wakefield"                       "2,075"   "1,954"   "1,927"  
    2012 "Female " "E12000004" "EAST MIDLANDS"                   "27,265"  "27,133"  "26,777" 
    2012 "Female " "E06000015" "Derby"                           "1,922"   "1,798"   "1,715"  
    2012 "Female " "E06000016" "Leicester"                       "2,621"   "2,504"   "2,390"  
    2012 "Female " "E06000018" "Nottingham"                      "2,140"   "1,927"   "1,950"  
    2012 "Female " "E06000017" "Rutland"                         "152"     "171"     "191"    
    2012 "Female " "E10000007" "Derbyshire"                      "4,096"   "4,154"   "4,081"  
    2012 "Female " "E07000032" "Amber Valley"                    "607"     "650"     "628"    
    2012 "Female " "E07000033" "Bolsover"                        "444"     "469"     "364"    
    2012 "Female " "E07000034" "Chesterfield"                    "598"     "577"     "568"    
    2012 "Female " "E07000035" "Derbyshire Dales"                "312"     "285"     "303"    
    2012 "Female " "E07000036" "Erewash"                         "663"     "646"     "666"    
    2012 "Female " "E07000037" "High Peak"                       "488"     "502"     "472"    
    2012 "Female " "E07000038" "North East Derbyshire"           "465"     "471"     "491"    
    2012 "Female " "E07000039" "South Derbyshire"                "519"     "554"     "589"    
    2012 "Female " "E10000018" "Leicestershire"                  "3,485"   "3,637"   "3,671"  
    2012 "Female " "E07000129" "Blaby"                           "487"     "544"     "548"    
    end

  • #2
    I appreciate that you made the effort to show us some example data, but because you only showed only one year and one gender, it doesn't illustrate your situation very well. So, I've simulated some data for just 3 locations, but with year/gender variation. I'm presuming you want your totals summed over years, but within code/age category/gender. See if this is like what you have and what you want:
    Code:
    clear
    // Simulate data that better illustrates what you have. 
    // I've ignored "name," which appears redundant.
    set obs 3  // just 3 locations
    gen str code = char(64+_n)
    expand 5 // years
    bysort code: gen year = 2011 + _n
    expand 2 // genders
    bysort code year: gen str gender = cond(_n==1, "Female", "Male")
    sort code year gender // to visualize
    forval i = 1/100 {
       gen str v`i' = strofreal(ceil(runiform()* 10000), "%8.0gc")
    }  // end simulate
    browse // Does this look like your data? I hope so.
    //
    // Your v* variables are stored as strings, not numbers.  To use them, we must convert
    // them to numbers.  See Remarks and Examples under -help destring- if this idea is unfamiliar.
    destring v1-v100, replace ignore(",")
    //
    // What you want is much easier if your data is in long format, with one
    // observation for every location, gender, and year.
    reshape long v, i(code gender year) j(age)
    //
    gen agecat = 10 * ceil(age/10) // Age categories as you want, coded with top of the decade
    drop age
    // Totals by code agecat gender, but summed over years.
    collapse (sum) v, by(agecat code gender)
    // To better visualize the result
    rename v numpersons
    order code agecat gender numpersons
    sort code gender agecat
    browse

    Comment


    • #3
      Hi Mike, Thanks for your response this is very helpful. How do I first add values by gender, and then build the categories from there?

      Comment


      • #4
        I have reshaped the data by the way.
        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input str36 name str9 code str7 gender int year float age long(allages v)
        "Hartlepool" "E06000001" "Female" 2013  0 47442 509
        "Hartlepool" "E06000001" "Female" 2013  1 47442 557
        "Hartlepool" "E06000001" "Female" 2013  2 47442 574
        "Hartlepool" "E06000001" "Female" 2013  3 47442 586
        "Hartlepool" "E06000001" "Female" 2013  4 47442 561
        "Hartlepool" "E06000001" "Female" 2013  5 47442 553
        "Hartlepool" "E06000001" "Female" 2013  6 47442 561
        "Hartlepool" "E06000001" "Female" 2013  7 47442 588
        "Hartlepool" "E06000001" "Female" 2013  8 47442 553
        "Hartlepool" "E06000001" "Female" 2013  9 47442 483
        "Hartlepool" "E06000001" "Female" 2013 10 47442 493
        "Hartlepool" "E06000001" "Female" 2013 11 47442 468
        "Hartlepool" "E06000001" "Female" 2013 12 47442 483
        "Hartlepool" "E06000001" "Female" 2013 13 47442 562
        "Hartlepool" "E06000001" "Female" 2013 14 47442 589
        "Hartlepool" "E06000001" "Female" 2013 15 47442 567
        "Hartlepool" "E06000001" "Female" 2013 16 47442 600
        "Hartlepool" "E06000001" "Female" 2013 17 47442 591
        "Hartlepool" "E06000001" "Female" 2013 18 47442 618
        "Hartlepool" "E06000001" "Female" 2013 19 47442 541
        "Hartlepool" "E06000001" "Female" 2013 20 47442 541
        "Hartlepool" "E06000001" "Female" 2013 21 47442 610
        "Hartlepool" "E06000001" "Female" 2013 22 47442 584
        "Hartlepool" "E06000001" "Female" 2013 23 47442 586
        "Hartlepool" "E06000001" "Female" 2013 24 47442 579
        "Hartlepool" "E06000001" "Female" 2013 25 47442 633
        "Hartlepool" "E06000001" "Female" 2013 26 47442 639
        "Hartlepool" "E06000001" "Female" 2013 27 47442 623
        "Hartlepool" "E06000001" "Female" 2013 28 47442 589
        "Hartlepool" "E06000001" "Female" 2013 29 47442 603
        "Hartlepool" "E06000001" "Female" 2013 30 47442 562
        "Hartlepool" "E06000001" "Female" 2013 31 47442 568
        "Hartlepool" "E06000001" "Female" 2013 32 47442 553
        "Hartlepool" "E06000001" "Female" 2013 33 47442 546
        "Hartlepool" "E06000001" "Female" 2013 34 47442 544
        "Hartlepool" "E06000001" "Female" 2013 35 47442 493
        "Hartlepool" "E06000001" "Female" 2013 36 47442 515
        "Hartlepool" "E06000001" "Female" 2013 37 47442 481
        "Hartlepool" "E06000001" "Female" 2013 38 47442 492
        "Hartlepool" "E06000001" "Female" 2013 39 47442 524
        "Hartlepool" "E06000001" "Female" 2013 40 47442 568
        "Hartlepool" "E06000001" "Female" 2013 41 47442 613
        "Hartlepool" "E06000001" "Female" 2013 42 47442 678
        "Hartlepool" "E06000001" "Female" 2013 43 47442 647
        "Hartlepool" "E06000001" "Female" 2013 44 47442 646
        "Hartlepool" "E06000001" "Female" 2013 45 47442 678
        "Hartlepool" "E06000001" "Female" 2013 46 47442 736
        "Hartlepool" "E06000001" "Female" 2013 47 47442 749
        "Hartlepool" "E06000001" "Female" 2013 48 47442 693
        "Hartlepool" "E06000001" "Female" 2013 49 47442 719
        "Hartlepool" "E06000001" "Female" 2013 50 47442 733
        "Hartlepool" "E06000001" "Female" 2013 51 47442 756
        "Hartlepool" "E06000001" "Female" 2013 52 47442 704
        "Hartlepool" "E06000001" "Female" 2013 53 47442 631
        "Hartlepool" "E06000001" "Female" 2013 54 47442 679
        "Hartlepool" "E06000001" "Female" 2013 55 47442 642
        "Hartlepool" "E06000001" "Female" 2013 56 47442 592
        "Hartlepool" "E06000001" "Female" 2013 57 47442 558
        "Hartlepool" "E06000001" "Female" 2013 58 47442 592
        "Hartlepool" "E06000001" "Female" 2013 59 47442 509
        "Hartlepool" "E06000001" "Female" 2013 60 47442 587
        "Hartlepool" "E06000001" "Female" 2013 61 47442 574
        "Hartlepool" "E06000001" "Female" 2013 62 47442 513
        "Hartlepool" "E06000001" "Female" 2013 63 47442 569
        "Hartlepool" "E06000001" "Female" 2013 64 47442 613
        "Hartlepool" "E06000001" "Female" 2013 65 47442 593
        "Hartlepool" "E06000001" "Female" 2013 66 47442 588
        "Hartlepool" "E06000001" "Female" 2013 67 47442 459
        "Hartlepool" "E06000001" "Female" 2013 68 47442 441
        "Hartlepool" "E06000001" "Female" 2013 69 47442 410
        "Hartlepool" "E06000001" "Female" 2013 70 47442 392
        "Hartlepool" "E06000001" "Female" 2013 71 47442 418
        "Hartlepool" "E06000001" "Female" 2013 72 47442 350
        "Hartlepool" "E06000001" "Female" 2013 73 47442 422
        "Hartlepool" "E06000001" "Female" 2013 74 47442 374
        "Hartlepool" "E06000001" "Female" 2013 75 47442 458
        "Hartlepool" "E06000001" "Female" 2013 76 47442 430
        "Hartlepool" "E06000001" "Female" 2013 77 47442 346
        "Hartlepool" "E06000001" "Female" 2013 78 47442 374
        "Hartlepool" "E06000001" "Female" 2013 79 47442 337
        "Hartlepool" "E06000001" "Female" 2013 80 47442 323
        "Hartlepool" "E06000001" "Female" 2013 81 47442 349
        "Hartlepool" "E06000001" "Female" 2013 82 47442 300
        "Hartlepool" "E06000001" "Female" 2013 83 47442 248
        "Hartlepool" "E06000001" "Female" 2013 84 47442 215
        "Hartlepool" "E06000001" "Female" 2013 85 47442 208
        "Hartlepool" "E06000001" "Female" 2013 86 47442 176
        "Hartlepool" "E06000001" "Female" 2013 87 47442 168
        "Hartlepool" "E06000001" "Female" 2013 88 47442 164
        "Hartlepool" "E06000001" "Female" 2013 89 47442 111
        "Hartlepool" "E06000001" "Female" 2013 90 47442 507
        "Hartlepool" "E06000001" "Female" 2014  0 47385 514
        "Hartlepool" "E06000001" "Female" 2014  1 47385 507
        "Hartlepool" "E06000001" "Female" 2014  2 47385 554
        "Hartlepool" "E06000001" "Female" 2014  3 47385 581
        "Hartlepool" "E06000001" "Female" 2014  4 47385 591
        "Hartlepool" "E06000001" "Female" 2014  5 47385 567
        "Hartlepool" "E06000001" "Female" 2014  6 47385 547
        "Hartlepool" "E06000001" "Female" 2014  7 47385 554
        "Hartlepool" "E06000001" "Female" 2014  8 47385 581
        end

        Comment


        • #5
          Sorry, I'm not sure what you mean by "add values by gender." To me, this would mean "add up the number of persons of each age across years but within gender?," which is already being done here. I also don't know what you mean by "build the categories."

          Comment


          • #6
            Hi Mike, I want to total the values by gender too so that I just have age categories for men and women together? Thank You

            Comment


            • #7
              OK, for that, you would want -collapse- to just give totals within code and gender, so you'd leave out agecat from its by list:
              Code:
              collapse (sum) v, by(code gender)

              Comment


              • #8
                This still doesnt work. Maybe I haven't been clear enough about what I want to happen
                I want to add together the number of men and women , so that I have the total number of W year old people that live in X local authority in Y year. And then I will create categories in the way suggested above, and then calculate the number of people in each category. Is there a way to merge the male and female variable v?

                Comment


                • #9
                  "Merge the male and female variable v" doesn't have a meaning for me. Among other things, gender rather than "v" is the male and female variable, and also because "merging" *variables* is not a terminology I'm familiar with. So, setting that aside, I'm guessing you want totals for numbers of persons, broken down separately for each distinct combination of location code, year, and age category.

                  If that's the case, and using your new example data, try
                  Code:
                  collapse (sum) v, by(code age year)
                  If that isn't doesn't result in what you want, please post a small (concocted) example of what you want your results to look like. That will be less subject to issues of language interpretation than would a verbal description.

                  I'd encourage you to take a look at the documentation (-help collapse- then "View complete PDF manual entry.") I think you should have enough information now that you'd be able to profit from that for this and future work, both for technique and terminology. I'd focus on the examples there first.


                  Comment


                  • #10
                    Hi Mike, I will try and be more clear as the solution is simple I am just unsure of the code. I do not need my data separated by gender, I just want to know the number of people each year within each age category. I hope this is clearer

                    Below is a sample of my data. I would like it to look like

                    "Hartlepool" "E06000001" "2012" "number of people in all of Hartlepool in 2012" "number of people between 0-10 in Hartlepool in 2012" "number of people between 11-20 in Hartlepool in 2012" ... "number of people 90+ in Hartlepool in 2012"
                    "Hartlepool" "E06000001" "2013" "number of people in all of Hartlepool in 2013" "number of people between 0-10 in Hartlepool in 2013" "number of people between 11-20 in Hartlepool in 2013" ... "number of people 90+ in Hartlepool in 2013"
                    "Hartlepool" "E06000001" "2014" "number of people in all of Hartlepool in 2014" "number of people between 0-10 in Hartlepool in 2013" "number of people between 11-20 in Hartlepool in 2014" ... "number of people 90+ in Hartlepool in 2012"

                    Code:
                    * Example generated by -dataex-. To install: ssc install dataex
                    clear
                    input str36 name str9 code str7 gender int year float age long(allages noofpeople) float agecat
                    "Hartlepool" "E06000001" "Female" 2015 56 47390 673 60
                    "Hartlepool" "E06000001" "Female" 2015 57 47390 637 60
                    "Hartlepool" "E06000001" "Female" 2015 58 47390 585 60
                    "Hartlepool" "E06000001" "Female" 2015 59 47390 547 60
                    "Hartlepool" "E06000001" "Female" 2015 60 47390 586 60
                    "Hartlepool" "E06000001" "Female" 2015 61 47390 493 70
                    "Hartlepool" "E06000001" "Female" 2015 62 47390 578 70
                    "Hartlepool" "E06000001" "Female" 2015 63 47390 555 70
                    "Hartlepool" "E06000001" "Female" 2015 64 47390 505 70
                    "Hartlepool" "E06000001" "Female" 2015 65 47390 556 70
                    "Hartlepool" "E06000001" "Female" 2015 66 47390 604 70
                    "Hartlepool" "E06000001" "Female" 2015 67 47390 582 70
                    "Hartlepool" "E06000001" "Female" 2015 68 47390 575 70
                    "Hartlepool" "E06000001" "Female" 2015 69 47390 446 70
                    "Hartlepool" "E06000001" "Female" 2015 70 47390 421 70
                    "Hartlepool" "E06000001" "Female" 2015 71 47390 396 80
                    "Hartlepool" "E06000001" "Female" 2015 72 47390 387 80
                    "Hartlepool" "E06000001" "Female" 2015 73 47390 411 80
                    "Hartlepool" "E06000001" "Female" 2015 74 47390 331 80
                    "Hartlepool" "E06000001" "Female" 2015 75 47390 409 80
                    "Hartlepool" "E06000001" "Female" 2015 76 47390 354 80
                    "Hartlepool" "E06000001" "Female" 2015 77 47390 441 80
                    "Hartlepool" "E06000001" "Female" 2015 78 47390 400 80
                    "Hartlepool" "E06000001" "Female" 2015 79 47390 309 80
                    "Hartlepool" "E06000001" "Female" 2015 80 47390 338 80
                    "Hartlepool" "E06000001" "Female" 2015 81 47390 313 90
                    "Hartlepool" "E06000001" "Female" 2015 82 47390 293 90
                    "Hartlepool" "E06000001" "Female" 2015 83 47390 305 90
                    "Hartlepool" "E06000001" "Female" 2015 84 47390 258 90
                    "Hartlepool" "E06000001" "Female" 2015 85 47390 218 90
                    "Hartlepool" "E06000001" "Female" 2015 86 47390 186 90
                    "Hartlepool" "E06000001" "Female" 2015 87 47390 182 90
                    "Hartlepool" "E06000001" "Female" 2015 88 47390 146 90
                    "Hartlepool" "E06000001" "Female" 2015 89 47390 120 90
                    "Hartlepool" "E06000001" "Female" 2015 90 47390 538 90
                    "Hartlepool" "E06000001" "Male"   2012  0 44865 595 10
                    "Hartlepool" "E06000001" "Male"   2012  1 44865 615 10
                    "Hartlepool" "E06000001" "Male"   2012  2 44865 586 10
                    "Hartlepool" "E06000001" "Male"   2012  3 44865 578 10
                    "Hartlepool" "E06000001" "Male"   2012  4 44865 616 10
                    "Hartlepool" "E06000001" "Male"   2012  5 44865 599 10
                    "Hartlepool" "E06000001" "Male"   2012  6 44865 547 10
                    "Hartlepool" "E06000001" "Male"   2012  7 44865 511 10
                    "Hartlepool" "E06000001" "Male"   2012  8 44865 538 10
                    "Hartlepool" "E06000001" "Male"   2012  9 44865 526 10
                    "Hartlepool" "E06000001" "Male"   2012 10 44865 504 10
                    "Hartlepool" "E06000001" "Male"   2012 11 44865 585 20
                    "Hartlepool" "E06000001" "Male"   2012 12 44865 547 20
                    "Hartlepool" "E06000001" "Male"   2012 13 44865 540 20
                    "Hartlepool" "E06000001" "Male"   2012 14 44865 532 20
                    "Hartlepool" "E06000001" "Male"   2012 15 44865 618 20
                    "Hartlepool" "E06000001" "Male"   2012 16 44865 631 20
                    "Hartlepool" "E06000001" "Male"   2012 17 44865 675 20
                    "Hartlepool" "E06000001" "Male"   2012 18 44865 655 20
                    "Hartlepool" "E06000001" "Male"   2012 19 44865 517 20
                    "Hartlepool" "E06000001" "Male"   2012 20 44865 611 20
                    "Hartlepool" "E06000001" "Male"   2012 21 44865 598 30
                    "Hartlepool" "E06000001" "Male"   2012 22 44865 558 30
                    "Hartlepool" "E06000001" "Male"   2012 23 44865 577 30
                    "Hartlepool" "E06000001" "Male"   2012 24 44865 613 30
                    "Hartlepool" "E06000001" "Male"   2012 25 44865 603 30
                    "Hartlepool" "E06000001" "Male"   2012 26 44865 566 30
                    "Hartlepool" "E06000001" "Male"   2012 27 44865 562 30
                    "Hartlepool" "E06000001" "Male"   2012 28 44865 530 30
                    "Hartlepool" "E06000001" "Male"   2012 29 44865 514 30
                    "Hartlepool" "E06000001" "Male"   2012 30 44865 512 30
                    "Hartlepool" "E06000001" "Male"   2012 31 44865 527 40
                    "Hartlepool" "E06000001" "Male"   2012 32 44865 539 40
                    "Hartlepool" "E06000001" "Male"   2012 33 44865 485 40
                    "Hartlepool" "E06000001" "Male"   2012 34 44865 427 40
                    "Hartlepool" "E06000001" "Male"   2012 35 44865 430 40
                    "Hartlepool" "E06000001" "Male"   2012 36 44865 479 40
                    "Hartlepool" "E06000001" "Male"   2012 37 44865 469 40
                    "Hartlepool" "E06000001" "Male"   2012 38 44865 499 40
                    "Hartlepool" "E06000001" "Male"   2012 39 44865 596 40
                    "Hartlepool" "E06000001" "Male"   2012 40 44865 591 40
                    "Hartlepool" "E06000001" "Male"   2012 41 44865 625 50
                    "Hartlepool" "E06000001" "Male"   2012 42 44865 623 50
                    "Hartlepool" "E06000001" "Male"   2012 43 44865 586 50
                    "Hartlepool" "E06000001" "Male"   2012 44 44865 606 50
                    end

                    Comment


                    • #11
                      Code:
                      * Example generated by -dataex-. To install: ssc install dataex
                      clear
                      input str36 name str9 code str7 gender int year float age long(allages noofpeople) float agecat
                      "Hartlepool" "E06000001" "Female" 2015 56 47390 673 60
                      "Hartlepool" "E06000001" "Female" 2015 57 47390 637 60
                      "Hartlepool" "E06000001" "Female" 2015 58 47390 585 60
                      "Hartlepool" "E06000001" "Female" 2015 59 47390 547 60
                      "Hartlepool" "E06000001" "Female" 2015 60 47390 586 60
                      "Hartlepool" "E06000001" "Female" 2015 61 47390 493 70
                      "Hartlepool" "E06000001" "Female" 2015 62 47390 578 70
                      "Hartlepool" "E06000001" "Female" 2015 63 47390 555 70
                      "Hartlepool" "E06000001" "Female" 2015 64 47390 505 70
                      "Hartlepool" "E06000001" "Female" 2015 65 47390 556 70
                      "Hartlepool" "E06000001" "Female" 2015 66 47390 604 70
                      "Hartlepool" "E06000001" "Female" 2015 67 47390 582 70
                      "Hartlepool" "E06000001" "Female" 2015 68 47390 575 70
                      "Hartlepool" "E06000001" "Female" 2015 69 47390 446 70
                      "Hartlepool" "E06000001" "Female" 2015 70 47390 421 70
                      "Hartlepool" "E06000001" "Female" 2015 71 47390 396 80
                      "Hartlepool" "E06000001" "Female" 2015 72 47390 387 80
                      "Hartlepool" "E06000001" "Female" 2015 73 47390 411 80
                      "Hartlepool" "E06000001" "Female" 2015 74 47390 331 80
                      "Hartlepool" "E06000001" "Female" 2015 75 47390 409 80
                      "Hartlepool" "E06000001" "Female" 2015 76 47390 354 80
                      "Hartlepool" "E06000001" "Female" 2015 77 47390 441 80
                      "Hartlepool" "E06000001" "Female" 2015 78 47390 400 80
                      "Hartlepool" "E06000001" "Female" 2015 79 47390 309 80
                      "Hartlepool" "E06000001" "Female" 2015 80 47390 338 80
                      "Hartlepool" "E06000001" "Female" 2015 81 47390 313 90
                      "Hartlepool" "E06000001" "Female" 2015 82 47390 293 90
                      "Hartlepool" "E06000001" "Female" 2015 83 47390 305 90
                      "Hartlepool" "E06000001" "Female" 2015 84 47390 258 90
                      "Hartlepool" "E06000001" "Female" 2015 85 47390 218 90
                      "Hartlepool" "E06000001" "Female" 2015 86 47390 186 90
                      "Hartlepool" "E06000001" "Female" 2015 87 47390 182 90
                      "Hartlepool" "E06000001" "Female" 2015 88 47390 146 90
                      "Hartlepool" "E06000001" "Female" 2015 89 47390 120 90
                      "Hartlepool" "E06000001" "Female" 2015 90 47390 538 90
                      "Hartlepool" "E06000001" "Male"   2012  0 44865 595 10
                      "Hartlepool" "E06000001" "Male"   2012  1 44865 615 10
                      "Hartlepool" "E06000001" "Male"   2012  2 44865 586 10
                      "Hartlepool" "E06000001" "Male"   2012  3 44865 578 10
                      "Hartlepool" "E06000001" "Male"   2012  4 44865 616 10
                      "Hartlepool" "E06000001" "Male"   2012  5 44865 599 10
                      "Hartlepool" "E06000001" "Male"   2012  6 44865 547 10
                      "Hartlepool" "E06000001" "Male"   2012  7 44865 511 10
                      "Hartlepool" "E06000001" "Male"   2012  8 44865 538 10
                      "Hartlepool" "E06000001" "Male"   2012  9 44865 526 10
                      "Hartlepool" "E06000001" "Male"   2012 10 44865 504 10
                      "Hartlepool" "E06000001" "Male"   2012 11 44865 585 20
                      "Hartlepool" "E06000001" "Male"   2012 12 44865 547 20
                      "Hartlepool" "E06000001" "Male"   2012 13 44865 540 20
                      "Hartlepool" "E06000001" "Male"   2012 14 44865 532 20
                      "Hartlepool" "E06000001" "Male"   2012 15 44865 618 20
                      "Hartlepool" "E06000001" "Male"   2012 16 44865 631 20
                      "Hartlepool" "E06000001" "Male"   2012 17 44865 675 20
                      "Hartlepool" "E06000001" "Male"   2012 18 44865 655 20
                      "Hartlepool" "E06000001" "Male"   2012 19 44865 517 20
                      "Hartlepool" "E06000001" "Male"   2012 20 44865 611 20
                      "Hartlepool" "E06000001" "Male"   2012 21 44865 598 30
                      "Hartlepool" "E06000001" "Male"   2012 22 44865 558 30
                      "Hartlepool" "E06000001" "Male"   2012 23 44865 577 30
                      "Hartlepool" "E06000001" "Male"   2012 24 44865 613 30
                      "Hartlepool" "E06000001" "Male"   2012 25 44865 603 30
                      "Hartlepool" "E06000001" "Male"   2012 26 44865 566 30
                      "Hartlepool" "E06000001" "Male"   2012 27 44865 562 30
                      "Hartlepool" "E06000001" "Male"   2012 28 44865 530 30
                      "Hartlepool" "E06000001" "Male"   2012 29 44865 514 30
                      "Hartlepool" "E06000001" "Male"   2012 30 44865 512 30
                      "Hartlepool" "E06000001" "Male"   2012 31 44865 527 40
                      "Hartlepool" "E06000001" "Male"   2012 32 44865 539 40
                      "Hartlepool" "E06000001" "Male"   2012 33 44865 485 40
                      "Hartlepool" "E06000001" "Male"   2012 34 44865 427 40
                      "Hartlepool" "E06000001" "Male"   2012 35 44865 430 40
                      "Hartlepool" "E06000001" "Male"   2012 36 44865 479 40
                      "Hartlepool" "E06000001" "Male"   2012 37 44865 469 40
                      "Hartlepool" "E06000001" "Male"   2012 38 44865 499 40
                      "Hartlepool" "E06000001" "Male"   2012 39 44865 596 40
                      "Hartlepool" "E06000001" "Male"   2012 40 44865 591 40
                      "Hartlepool" "E06000001" "Male"   2012 41 44865 625 50
                      "Hartlepool" "E06000001" "Male"   2012 42 44865 623 50
                      "Hartlepool" "E06000001" "Male"   2012 43 44865 586 50
                      "Hartlepool" "E06000001" "Male"   2012 44 44865 606 50
                      end
                      //
                      drop age allages // irrelevant
                      collapse (sum) noofpeople, by(code name year agecat)
                      reshape wide noofpeople, i(code year) j(agecat)
                      egen NumAllAges = rowtotal(noofpeople*)
                      order NumAllAges, after(year)




                      Comment


                      • #12
                        This is great! Thank you again Mike!

                        Comment

                        Working...
                        X