Announcement

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

  • Coding Operator Not Allowed error using bysort var: gen newvar=_n

    Hello,
    I want to to assign an id number for each distinct psal_code within sapid, but I receive the error message "coding operators not allowed" when attempting to do so with the following code:

    bysort sapid(psal_code): gen id=_n
    coding operators not allowed
    r(198);

    What does this error mean within the context of this code and how can I achieve what I seeking to do? Thank you so much for your advice!



    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str6 dbn str70 school_name str59 psal_name int psal_code str3 sap_school str11 sap_status byte sapid str7 sap_year_created str2 district
    "01M539" "New Explorations into Science, Technology and Math (NEST+M)"            "New Explorations into Science, Technology and Math (NEST+M)"  1538 "Yes" "Completed"   13 "2021-22" "01"
    "01M292" "Orchard Collegiate Academy"                                             "Orchard Collegiate Academy"                                   1552 "Yes" "Pilot"        7 "2018-19" "01"
    "01M696" "Bard High School Early College"                                         "Bard High School Early College"                               1569 "Yes" "Completed"   13 "2021-22" "01"
    "02M260" "The Clinton School"                                                     "The Clinton School"                                           2260 "Yes" "Pending"     28 "2023-24" "02"
    "02M489" "High School of Economics and Finance"                                   "High School of Economics and Finance"                         2350 "Yes" "In-progress" 29 "2023-24" "02"
    "02M439" "Manhattan Village Academy"                                              "Manhattan Village Academy"                                    2358 "Yes" "Pending"     28 "2023-24" "02"
    "02M425" "Leadership and Public Service High School"                              "Leadership and Public Service High School"                    2370 "Yes" "In-progress" 29 "2023-24" "02"
    "02M413" "School of the Future High School"                                       "School of the Future High School"                             2436 "Yes" "Pending"     28 "2023-24" "02"
    "01M448" "University Neighborhood High School"                                    "University Neighborhood High School"                          2516 "Yes" "Pilot"        7 "2018-19" "01"
    "02M534" "Harvest Collegiate High School"                                         "Washington Irving"                                            2521 "Yes" "Completed"   27 "2021-22" "02"
    "02M399" "The High School For Language And Diplomacy"                             "Washington Irving"                                            2521 "Yes" "Completed"   27 "2021-22" "02"
    "02M533" "Union Square Academy for Health Sciences"                               "Washington Irving"                                            2521 "Yes" "Completed"   27 "2021-22" "02"
    "02M438" "International High School at Union Square"                              "Washington Irving"                                            2521 "Yes" "Completed"   27 "2021-22" "02"
    "02M546" "Academy for Software Engineering"                                       "Washington Irving"                                            2521 "Yes" "Completed"   27 "2021-22" "02"
    "02M374" "Gramercy Arts High School"                                              "Washington Irving"                                            2521 "Yes" "Completed"   27 "2021-22" "02"
    "02M432" "Murray Hill Academy"                                                    "Norman Thomas"                                                2523 "Yes" "In-progress" 26 "2023-24" "02"
    "02M500" "Unity Center for Urban Technologies"                                    "Norman Thomas"                                                2523 "Yes" "In-progress" 26 "2023-24" "02"
    "02M427" "MANHATTAN ACADEMY FOR ARTS & LANGUAGE"                                  "Norman Thomas"                                                2523 "Yes" "In-progress" 26 "2023-24" "02"
    "02M580" "Richard R. Green High School of Teaching"                               "Richard R Green"                                              2524 "Yes" "Completed"   17 "2021-22" "02"
    "02M316" "Urban Assembly School of Business for Young Women"                      "Richard R Green"                                              2524 "Yes" "Completed"   17 "2021-22" "02"
    "02M393" "Business Of Sports School"                                              "Graphics Campus"                                              2541 "Yes" "Completed"   18 "2021-22" "02"
    "02M529" "Jacqueline Kennedy Onassis High School"                                 "Graphics Campus"                                              2541 "Yes" "Completed"   18 "2021-22" "02"
    "02M139" "Stephen T. Mather Building Arts & Craftsmanship Hi"                     "Graphics Campus"                                              2541 "Yes" "Completed"   18 "2021-22" "02"
    "02M408" "Professional Performing Arts High School"                               "Graphics Campus"                                              2541 "Yes" "Completed"   18 "2021-22" "02"
    "02M507" "Urban Assembly Gateway School for Technology"                           "Graphics Campus"                                              2541 "Yes" "Completed"   18 "2021-22" "02"
    "02M531" "Repertory Company High School for Theatre Arts"                         "Graphics Campus"                                              2541 "Yes" "Completed"   18 "2021-22" "02"
    "02M411" "Baruch College Campus High School"                                      "Baruch College Campus High School"                            2875 "Yes" "In-progress" 26 "2023-24" "02"
    "03M415" "Wadleigh Secondary School for the Performing & Visual Arts"             "Wadleigh Secondary School"                                    3325 "Yes" "Pending"     20 "2023-24" "03"
    "04M372" "Esperanza Preparatory Academy"                                          "Esperanza Preparatory Academy"                                4373 "Yes" "Pending"     20 "2023-24" "04"
    "04M680" "Heritage School, The"                                                   "East Harlem Pride"                                            4565 "Yes" "Pending"     20 "2023-24" "04"
    "04M555" "Central Park East High School"                                          "East Harlem Pride"                                            4565 "Yes" "Pending"     20 "2023-24" "04"
    "04M610" "Young Women's Leadership School"                                        "East Harlem Pride"                                            4565 "Yes" "Pending"     20 "2023-24" "04"
    "03M860" "Frederick Douglass Academy II Secondary School"                         "East Harlem Pride"                                            4565 "Yes" "Pending"     20 "2023-24" "03"
    "04M495" "Park East High School"                                                  "East Harlem Pride"                                            4565 "Yes" "Pending"     20 "2023-24" "04"
    "05M362" "Columbia Secondary School"                                              "Columbia Secondary School"                                    5362 "Yes" "In-progress" 25 "2023-24" "05"
    "05M670" "Thurgood Marshall Academy"                                              "Thurgood Marshall Academy"                                    5365 "Yes" "In-progress" 25 "2023-24" "05"
    "05M369" "Urban Assembly School for the Performing Arts"                          "Urban Assembly School for the Performing Arts"                5367 "Yes" "Completed"   11 "2022-23" "05"
    "05M148" "Eagle Academy for Young Men of Harlem"                                  "Percy E Sutton Educational Campus"                            5460 "Yes" "Completed"   11 "2022-23" "05"
    "05M304" "Mott Hall High School"                                                  "Percy E Sutton Educational Campus"                            5460 "Yes" "Completed"   11 "2022-23" "05"
    "06M346" "Community Health Academy of the Heights"                                "Community Health Academy of the Heights"                      6346 "Yes" "In-progress" 30 "2023-24" "06"
    "06M552" "Gregorio Luperon High School for Science and Mathematics"               "Gregorio Luperon High School for Science and Mathematics"     6427 "Yes" "In-progress" 30 "2023-24" "06"
    "07X500" "Hostos-Lincoln Academy of Science"                                      "Hostos Lincoln / University Prep"                             7401 "Yes" "In-progress" 31 "2023-24" "07"
    "84X393" "University Prep Charter High School"                                    "Hostos Lincoln / University Prep"                             7401 "Yes" "In-progress" 31 "2023-24" "84"
    "09X505" "Bronx School for Law, Government, and Justice"                          "Bronx School for Law, Government, and Justice"                7402 "Yes" "Pilot"        4 "2018-19" "09"
    "07X427" "Community School for Social Justice"                                    "Bronx United"                                                 7498 "Yes" "Completed"   12 "2021-22" "07"
    "07X551" "The Urban Assembly Bronx Academy of Letters"                            "Bronx United"                                                 7498 "Yes" "Completed"   12 "2021-22" "07"
    "07X670" "Health Opportunities High School"                                       "Bronx United"                                                 7498 "Yes" "Completed"   12 "2021-22" "07"
    "84X202" "New Visions Charter School for Advanced Math"                           "Samuel Gompers"                                               7525 "Yes" "In-progress" 31 "2023-24" "84"
    "07X259" "H.E.R.O. High (Health, Education, and Research Occ"                     "Samuel Gompers"                                               7525 "Yes" "In-progress" 31 "2023-24" "07"
    "84X208" "New Visions Charter High School for the Humanities"                     "Samuel Gompers"                                               7525 "Yes" "In-progress" 31 "2023-24" "84"
    "08X367" "Archimedes Academy for Math, Science and Technology"                    "Archimedes/Maleska Campus"                                    8367 "Yes" "Pending"     24 "2023-24" "08"
    "08X282" "Women's Academy of Excellence"                                          "Archimedes/Maleska Campus"                                    8367 "Yes" "Pending"     24 "2023-24" "08"
    "08X377" "Bronx Community High School"                                            "Adlai Stevenson Campus"                                       8527 "Yes" "Pending"     24 "2023-24" "08"
    "08X376" "Antonia Pantoja Preparatory Academy: A College Boa"                     "Adlai Stevenson Campus"                                       8527 "Yes" "Pending"     24 "2023-24" "08"
    "08X452" "Gotham Collaborative High School"                                       "Adlai Stevenson Campus"                                       8527 "Yes" "Pending"     24 "2023-24" "08"
    "08X561" "Bronx Compass High School"                                              "Adlai Stevenson Campus"                                       8527 "Yes" "Pending"     24 "2023-24" "08"
    "08X312" "Millennium Art Academy"                                                 "Adlai Stevenson Campus"                                       8527 "Yes" "Pending"     24 "2023-24" "08"
    "09X250" "Eximius College Preparatory Academy: A College Boa- Morrisania Campus " "Morrisania Educational Campus"                                9260 "Yes" "In-progress" 15 "2023-24" "09"
    "09X260" "Bronx Center for Science and Mathematics-Morrisania Campus "            "Morrisania Educational Campus"                                9260 "Yes" "In-progress" 15 "2023-24" "09"
    "09X324" "Bronx Early College Academy for Teaching & Learning"                    "Bronx Early College Academy for Teaching & Learning"          9324 "Yes" "Pilot"        4 "2018-19" "09"
    "09X327" "Comprehensive Model School Project M.S. 327 12"                         "Comprehensive Model School Project M.S. 327 12"               9327 "Yes" "Pilot"        3 "2018-19" "09"
    "09X365" "Academy for Language and Technology"                                    "Academy for Language and Technology"                          9365 "Yes" "Pilot"        3 "2018-19" "09"
    "09X231" "Eagle Academy for Young Men"                                            "Eagle Academy for Young Men"                                  9458 "Yes" "In-progress" 14 "2023-24" "09"
    "09X517" "Frederick Douglass Academy III Secondary School"                        "Frederick Douglass Academy III"                               9471 "Yes" "In-progress" 15 "2023-24" "09"
    "09X525" "Bronx Leadership Academy High School"                                   "Bronx Leadership Academy "                                    9490 "Yes" "In-progress" 14 "2023-24" "09"
    "09X568" "Young Women's Leadership School of the Bronx"                           "Young Women's Leadership School of the Bronx"                 9569 "Yes" "Pilot"        3 "2018-19" "09"
    "10X368" "In-Tech Academy"                                                        "In-Tech Academy"                                             10368 "Yes" "Completed"   16 "2021-22" "10"
    "10X213" "Bronx Engineering and Technology Academy"                               "John F Kennedy Campus"                                       10526 "Yes" "Completed"   16 "2021-22" "10"
    "84X539" "New Visions Charter High School for Advanced Math"                      "John F Kennedy Campus"                                       10526 "Yes" "Completed"   16 "2021-22" "84"
    "10X284" "Bronx School of Law and Finance"                                        "John F Kennedy Campus"                                       10526 "Yes" "Completed"   16 "2021-22" "10"
    "10X546" "Bronx Theatre High School"                                              "John F Kennedy Campus"                                       10526 "Yes" "Completed"   16 "2021-22" "10"
    "84X553" "New Visions Charter High School for the Humanities"                     "John F Kennedy Campus"                                       10526 "Yes" "Completed"   16 "2021-22" "84"
    "10X477" "Marble Hill High School for International Studies"                      "John F Kennedy Campus"                                       10526 "Yes" "Completed"   16 "2021-22" "10"
    "10X397" "English Language Learners and International Support"                    "John F Kennedy Campus"                                       10526 "Yes" "Completed"   16 "2021-22" "10"
    "12X251" "Explorations Academy H.S."                                              "Explorations Academy"                                        12251 "Yes" "Pilot"        2 "2018-19" "12"
    "12X511" "Bronx Envision Academy"                                                 "Explorations Academy"                                        12251 "Yes" "Pilot"        2 "2018-19" "12"
    "84X482" "Dr. Richard Izquierdo Health and Science Charter School"                "The Bronx Latin School"                                      12546 "Yes" "Pilot"        1 "2018-19" "84"
    "12X267" "Bronx Latin"                                                            "The Bronx Latin School"                                      12546 "Yes" "Pilot"        1 "2018-19" "12"
    "12X479" "Bronx Career and College Preparatory High School"                       "The Bronx Latin School"                                      12546 "Yes" "Pilot"        1 "2018-19" "12"
    "12X248" "The Metropolitan High School"                                           "The Metropolitan High School"                                12552 "Yes" "Pilot"        1 "2018-19" "12"
    "12X271" "East Bronx Academy for the Future"                                      "East Bronx Academy for the Future"                           12937 "Yes" "Pilot"        2 "2018-19" "12"
    "14K071" "Juan Morel Campos Secondary School"                                     "Juan Morel Campos Secondary School"                          14071 "Yes" "Completed"    8 "2022-23" "14"
    "14K685" "El Puente Academy for Peace and Justice"                                "Juan Morel Campos Secondary School"                          14071 "Yes" "Completed"    8 "2022-23" "14"
    "14K454" "The Williamsburg High School of Art and Technology"                     "Gaynor Campus"                                               14449 "Yes" "Completed"    8 "2022-23" "14"
    "14K449" "The Brooklyn Latin School"                                              "Gaynor Campus"                                               14449 "Yes" "Completed"    8 "2022-23" "14"
    "14K586" "Lyons Community School"                                                 "Gaynor Campus"                                               14449 "Yes" "Completed"    8 "2022-23" "14"
    "15K429" "Digital Arts and Cinema Technology High School"                         "Boerum Hill School & Digital Tech"                           15567 "Yes" "In-progress"  9 "2023-24" "15"
    "15K497" "The Boerum Hill School for International Studies"                       "Boerum Hill School & Digital Tech"                           15567 "Yes" "In-progress"  9 "2023-24" "15"
    "16K498" "Brooklyn High School for Law and Technology"                            "Brooklyn High School for Law and Technology"                 15568 "Yes" "In-progress" 10 "2023-24" "16"
    "15K519" "Cobble Hill School of American Studies"                                 "Cobble Hill School of American Studies"                      15569 "Yes" "In-progress"  9 "2023-24" "15"
    "15K656" "Brooklyn High School of the Arts"                                       "Brooklyn High School of the Arts"                            15570 "Yes" "In-progress" 32 "2023-24" "15"
    "15K592" "Khalil Gibran International Academy"                                    "Khalil Gibran International Academy"                         15592 "Yes" "In-progress" 32 "2023-24" "15"
    "84K892" "Brooklyn Emerging Leaders Academy- charter"                             "Brooklyn Academy of Global Finance"                          16688 "Yes" "In-progress" 10 "2023-24" "84"
    "16K688" "Brooklyn Academy of Global Finance"                                     "Brooklyn Academy of Global Finance"                          16688 "Yes" "In-progress" 10 "2023-24" "16"
    "17K590" "Medgar Evers College Preparatory School"                                "Medgar Evers College Preparatory School"                     17300 "Yes" "Pending"     21 "2023-24" "17"
    "17K600" "Clara Barton High School"                                               "Clara Barton "                                               17549 "Yes" "Pending"     21 "2023-24" "17"
    "23K697" "Teachers Preparatory High School"                                       "Teachers Preparatory HS/FDA VII"                             17559 "Yes" "Pilot"        6 "2018-19" "23"
    "23K514" "Frederick Douglass Academy VII High School"                             "Teachers Preparatory HS/FDA VII"                             17559 "Yes" "Pilot"        6 "2018-19" "23"
    "19K615" "Transit Tech Career and Technical Education High School"                "Transit Tech Career and Technical Education High School"     19551 "Yes" "Completed"   19 "2022-23" "19"
    "19K683" "School for Classics High School"                                        "School for Classics High School"                             19683 "Yes" "Completed"   19 "2022-23" "19"
    end
    ------------------ copy up to and including the previous line ------------------

    Listed 100 out of 116 observations
    Use the count() option to list more

    I am attempting to calculate a sum of the var by sapid. However, I only want to total the var for each distinct psal_code within this group. but only for the first observation of a different psal_code within a the sapid group.

  • #2
    bysort sapid(psal_code): gen id=_n
    coding operators not allowed
    r(198);
    You need to put a space between sapid and (psal_code).
    Code:
    bysort sapid (psal_code): gen id=_n
    eliminates the error message. But it does not do what you say you want to do. You want a new id number for each distinct psal_code within sap_id. The code simply assigns consecutive numbers to observations, sorted in order of psal_code, within sapid. When you have two observations with the same sapid and psal_code, they will get different id's with that code. What you want is:
    Code:
    bysort sapid (psal_code): gen id = sum(psal_code != psal_code[_n-1])

    Comment

    Working...
    X