Announcement

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

  • Count how many units have the dummy variable=1

    Hi
    I have data for 353 local authorities over 20 quarters and one of my variables is a dummy variable that takes the value 1 or zero if that local authority is a unitary authority or not and this does not change over time.
    Is there a way to easily count how many separate local authorities are unitary? I predict around 55 are unitary but as the data is in long format this is tedious to count. All of the local authorities below are unitary, but for many in my sample this dummy takes the value 0. 'acode' is just a numeric identity for each local authority.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str43 name float acode byte unitarydummy
    "Hartlepool Borough Council"           6000001 1
    "Hartlepool Borough Council"           6000001 1
    "Hartlepool Borough Council"           6000001 1
    "Hartlepool Borough Council"           6000001 1
    "Hartlepool Borough Council"           6000001 1
    "Hartlepool Borough Council"           6000001 1
    "Hartlepool Borough Council"           6000001 1
    "Hartlepool Borough Council"           6000001 1
    "Hartlepool Borough Council"           6000001 1
    "Hartlepool Borough Council"           6000001 1
    "Hartlepool Borough Council"           6000001 1
    "Hartlepool Borough Council"           6000001 1
    "Hartlepool Borough Council"           6000001 1
    "Hartlepool Borough Council"           6000001 1
    "Hartlepool Borough Council"           6000001 1
    "Hartlepool Borough Council"           6000001 1
    "Hartlepool Borough Council"           6000001 1
    "Hartlepool Borough Council"           6000001 1
    "Hartlepool Borough Council"           6000001 1
    "Hartlepool Borough Council"           6000001 1
    "Middlesbrough Borough Council"        6000002 1
    "Middlesbrough Borough Council"        6000002 1
    "Middlesbrough Borough Council"        6000002 1
    "Middlesbrough Borough Council"        6000002 1
    "Middlesbrough Borough Council"        6000002 1
    "Middlesbrough Borough Council"        6000002 1
    "Middlesbrough Borough Council"        6000002 1
    "Middlesbrough Borough Council"        6000002 1
    "Middlesbrough Borough Council"        6000002 1
    "Middlesbrough Borough Council"        6000002 1
    "Middlesbrough Borough Council"        6000002 1
    "Middlesbrough Borough Council"        6000002 1
    "Middlesbrough Borough Council"        6000002 1
    "Middlesbrough Borough Council"        6000002 1
    "Middlesbrough Borough Council"        6000002 1
    "Middlesbrough Borough Council"        6000002 1
    "Middlesbrough Borough Council"        6000002 1
    "Middlesbrough Borough Council"        6000002 1
    "Middlesbrough Borough Council"        6000002 1
    "Middlesbrough Borough Council"        6000002 1
    "Redcar and Cleveland Borough Council" 6000003 1
    "Redcar and Cleveland Borough Council" 6000003 1
    "Redcar and Cleveland Borough Council" 6000003 1
    "Redcar and Cleveland Borough Council" 6000003 1
    "Redcar and Cleveland Borough Council" 6000003 1
    "Redcar and Cleveland Borough Council" 6000003 1
    "Redcar and Cleveland Borough Council" 6000003 1
    "Redcar and Cleveland Borough Council" 6000003 1
    "Redcar and Cleveland Borough Council" 6000003 1
    "Redcar and Cleveland Borough Council" 6000003 1
    "Redcar and Cleveland Borough Council" 6000003 1
    "Redcar and Cleveland Borough Council" 6000003 1
    "Redcar and Cleveland Borough Council" 6000003 1
    "Redcar and Cleveland Borough Council" 6000003 1
    "Redcar and Cleveland Borough Council" 6000003 1
    "Redcar and Cleveland Borough Council" 6000003 1
    "Redcar and Cleveland Borough Council" 6000003 1
    "Redcar and Cleveland Borough Council" 6000003 1
    "Redcar and Cleveland Borough Council" 6000003 1
    "Redcar and Cleveland Borough Council" 6000003 1
    "Stockton-on-Tees Borough Council"     6000004 1
    "Stockton-on-Tees Borough Council"     6000004 1
    "Stockton-on-Tees Borough Council"     6000004 1
    "Stockton-on-Tees Borough Council"     6000004 1
    "Stockton-on-Tees Borough Council"     6000004 1
    "Stockton-on-Tees Borough Council"     6000004 1
    "Stockton-on-Tees Borough Council"     6000004 1
    "Stockton-on-Tees Borough Council"     6000004 1
    "Stockton-on-Tees Borough Council"     6000004 1
    "Stockton-on-Tees Borough Council"     6000004 1
    "Stockton-on-Tees Borough Council"     6000004 1
    "Stockton-on-Tees Borough Council"     6000004 1
    "Stockton-on-Tees Borough Council"     6000004 1
    "Stockton-on-Tees Borough Council"     6000004 1
    "Stockton-on-Tees Borough Council"     6000004 1
    "Stockton-on-Tees Borough Council"     6000004 1
    "Stockton-on-Tees Borough Council"     6000004 1
    "Stockton-on-Tees Borough Council"     6000004 1
    "Stockton-on-Tees Borough Council"     6000004 1
    "Stockton-on-Tees Borough Council"     6000004 1
    "Darlington Borough Council"           6000005 1
    "Darlington Borough Council"           6000005 1
    "Darlington Borough Council"           6000005 1
    "Darlington Borough Council"           6000005 1
    "Darlington Borough Council"           6000005 1
    "Darlington Borough Council"           6000005 1
    "Darlington Borough Council"           6000005 1
    "Darlington Borough Council"           6000005 1
    "Darlington Borough Council"           6000005 1
    "Darlington Borough Council"           6000005 1
    "Darlington Borough Council"           6000005 1
    "Darlington Borough Council"           6000005 1
    "Darlington Borough Council"           6000005 1
    "Darlington Borough Council"           6000005 1
    "Darlington Borough Council"           6000005 1
    "Darlington Borough Council"           6000005 1
    "Darlington Borough Council"           6000005 1
    "Darlington Borough Council"           6000005 1
    "Darlington Borough Council"           6000005 1
    "Darlington Borough Council"           6000005 1
    end

  • #2
    Code:
    egen tag = tag(name) 
    count if dummy & tag 
    
    
    tab name if dummy 
    di r(r)

    Comment


    • #3
      Hi Nick,
      egen tag = tag(acode)
      Below is my output- Im not sure how it tells me how many local authorities there are?

      . count if unitarydummy & tag
      90

      .
      .
      . tab name if unitarydummy

      name | Freq. Percent Cum.
      ----------------------------------------+-----------------------------------
      Barnsley MBC | 20 1.11 1.11
      Bath and North East Somerset Council | 20 1.11 2.22
      Bedford | 20 1.11 3.33
      Bexley LB | 20 1.11 4.44
      Birmingham City Council | 20 1.11 5.56
      Blackburn with Darwen Borough Council | 20 1.11 6.67
      Blackpool Borough Council | 20 1.11 7.78
      Bournemouth Borough Council | 20 1.11 8.89
      Bracknell Forest Borough Council | 20 1.11 10.00
      Bradford City MDC (MBC) | 20 1.11 11.11
      Brighton and Hove Council | 20 1.11 12.22
      Bristol City Council | 20 1.11 13.33
      Bromley LB | 20 1.11 14.44
      Calderdale MBC | 20 1.11 15.56
      Central Bedfordshire | 20 1.11 16.67
      Cheshire East | 20 1.11 17.78
      Cheshire West and Chester | 20 1.11 18.89
      City of London | 20 1.11 20.00
      Cornwall | 20 1.11 21.11
      Council of the Isles of Scilly | 20 1.11 22.22
      County Durham | 20 1.11 23.33
      Coventry City Council | 20 1.11 24.44
      Croydon LB | 20 1.11 25.56
      Darlington Borough Council | 20 1.11 26.67
      Derby City Council | 20 1.11 27.78
      Doncaster MBC | 20 1.11 28.89
      Dudley MBC | 20 1.11 30.00
      East Riding of Yorkshire Council | 20 1.11 31.11
      Gateshead MBC | 20 1.11 32.22
      Greenwich LB | 20 1.11 33.33
      Halton Borough Council | 20 1.11 34.44
      Hartlepool Borough Council | 20 1.11 35.56
      Herefordshire Council | 20 1.11 36.67
      Isle of Wight Council | 20 1.11 37.78
      Kingston upon Thames | 20 1.11 38.89
      Kingston-upon-Hull City Council | 20 1.11 40.00
      Kirklees MBC | 20 1.11 41.11
      Leeds City Council MBC | 20 1.11 42.22
      Leicester City Council | 20 1.11 43.33
      Lewisham LB | 20 1.11 44.44
      Luton Borough Council | 20 1.11 45.56
      Medway Borough Council | 20 1.11 46.67
      Merton LB | 20 1.11 47.78
      Middlesbrough Borough Council | 20 1.11 48.89
      Milton Keynes Council | 20 1.11 50.00
      Newcastle-upon-Tyne City Council MBC | 20 1.11 51.11
      North East Lincolnshire Council | 20 1.11 52.22
      North Lincolnshire Council | 20 1.11 53.33
      North Somerset Council | 20 1.11 54.44
      North Tyneside Council | 20 1.11 55.56
      Northumberland | 20 1.11 56.67
      Nottingham City Council | 20 1.11 57.78
      Peterborough City Council | 20 1.11 58.89
      Plymouth City Council | 20 1.11 60.00
      Poole Borough Council | 20 1.11 61.11
      Portsmouth City Council | 20 1.11 62.22
      Reading Borough Council | 20 1.11 63.33
      Redcar and Cleveland Borough Council | 20 1.11 64.44
      Rotherham MBC | 20 1.11 65.56
      Rutland County Council | 20 1.11 66.67
      Sandwell MBC | 20 1.11 67.78
      Sheffield City Council | 20 1.11 68.89
      Shropshire | 20 1.11 70.00
      Slough Borough Council | 20 1.11 71.11
      Solihull MBC | 20 1.11 72.22
      South Gloucestershire Council | 20 1.11 73.33
      South Tyneside MBC | 20 1.11 74.44
      Southampton City Council | 20 1.11 75.56
      Southend-on-Sea Borough Council | 20 1.11 76.67
      Southwark LB | 20 1.11 77.78
      Stockton-on-Tees Borough Council | 20 1.11 78.89
      Stoke-on-Trent City Council | 20 1.11 80.00
      Sunderland City Council | 20 1.11 81.11
      Sutton LB | 20 1.11 82.22
      Swindon Borough Council | 20 1.11 83.33
      Telford and Wrekin Council | 20 1.11 84.44
      Thurrock Council | 20 1.11 85.56
      Torbay Council | 20 1.11 86.67
      Tower Hamlets LB | 20 1.11 87.78
      Wakefield City MDC | 20 1.11 88.89
      Walsall MBC | 20 1.11 90.00
      Warrington Borough Council | 20 1.11 91.11
      West Berkshire District Council | 20 1.11 92.22
      Westminster City Council | 20 1.11 93.33
      Wigan MBC | 20 1.11 94.44
      Wiltshire | 20 1.11 95.56
      Windsor and Maidenhead Borough Council | 20 1.11 96.67
      Wokingham Council | 20 1.11 97.78
      Wolverhampton MBC | 20 1.11 98.89
      York City Council | 20 1.11 100.00
      ----------------------------------------+-----------------------------------
      Total | 1,800 100.00

      . di r(r)
      90


      Comment


      • #4


        You are being told that there are 90 of them, in two different ways.

        I am British, as you may have gathered, so I should understand about unitary authorities, but I can't tell you off-hand which of these is or is not unitary, or comment on why you think there should be 55.

        Longer answer: My code was written on the assumption that your statement is correct, so that (e.g.)

        Code:
        tab name if dummy 
        is then exactly equivalent to
        Code:
          
         tab name if dummy == 1
        as a dummy (indicator is my view a much better term, but there you go) is then true (non-zero) if and only if it is 1 -- as explained at (e.g) https://www.stata.com/support/faqs/d...lse/index.html

        If your dummy is not in fact just 1 or 0, but may take on other values, then you do need to spell out all of
        Code:
        ... if dummy == 1
        as any non-zero value (including missing) also counts as true.

        Comment


        • #5
          Thank you Nick- this was very helpful. Turns out in my sample Metropolitan Districts were also counted as local authorities (they are pretty much the same since the Local Government Act 1985 and I hadn't realised.

          Comment

          Working...
          X