Announcement

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

  • Delimiters not working

    Hi all,

    I have a large individual-level dataset on jobs. One of the variables is Industry of Work (named: "ind_3dig_p") that identifies, for each person, which industry they work in if they are employed. The variable is a 3-digit code. There is a mapping of codes to industries which I have in a separate file.

    For instance,
    011 "Growing of non-perennial crops"
    015 "Mixed farming" ....and so on...410 "Construction of buildings "...all the way till 990.

    I want to add the above labels for these 3 digit codes into my dataset so that I can sort by industry or analyze jobs in a particular industry etc.

    Since I have a large number of variables, I want the flexibility of having my codes on different lines using the delimit command. I try to do this as follows:

    #delimit ;
    label define ind_3dig_label 11 "Growing of non-perennial crops"
    12 "Growing of perennial crops"

    ....
    982 "Undifferentiated service-producing activities "
    990 "Activities of households" ;
    #delimit cr
    la values ind_3dig_p ind_3dig_label

    However, STATA gives me the following error message, indicating it is getting stuck at the second line of code itself.
    "12 is not a valid command name"

    Any ideas on how to fix this or another way to get my label values into the dataset? I am running this through my do-file not the command box so that is not the issue.

    Thanks in advance.

  • #2
    Your code worked fine for me. The following code:
    Code:
    #delimit ; 
    label define ind_3dig_label 11 "Growing of non-perennial crops"
    12 "Growing of perennial crops"
    982 "Undifferentiated service-producing activities "
    990 "Activities of households" ; 
    #delimit cr
    produced the following output:
    Code:
    . #delimit ; 
    delimiter now ;
    . label define ind_3dig_label 11 "Growing of non-perennial crops"
    > 12 "Growing of perennial crops"
    > 982 "Undifferentiated service-producing activities "
    > 990 "Activities of households" ;
    
    .  #delimit cr
    delimiter now cr
    . 
    end of do-file
    
    . label list ind_3dig_label
    ind_3dig_label:
              11 Growing of non-perennial crops
              12 Growing of perennial crops
             982 Undifferentiated service-producing activities 
             990 Activities of households
    Best,
    Alan

    Comment


    • #3
      Hi Alan, Thanks for this. You're right when I try pasting in just the bit of code that I sent you, it works for me too.

      However, when I try the full code, it gives me an error message of either "12 is not a valid command name" or "Invalid Syntax". here is the full list of variable labels. Do you get the same error message?
      #delimit ;
      label define ind_3dig_label 11 "Growing of non-perennial crops"
      12 "Growing of perennial crops"
      13 "Plant propagation"
      14 "Animal production"
      15 "Mixed farming"
      16 "Support activities to agriculture and post-harvest crop activities"
      17 "Hunting, trapping and related service activities"
      21 "Silviculture and other forestry activities"
      22 "Logging"
      23 "Gathering of non-wood forest products"
      24 "Support services to forestry"
      31 "Fishing"
      32 "Aquaculture"
      51 "Mining of hard coal"
      52 "Mining of lignite"
      61 "Extraction of crude petroleum"
      62 "Extraction of natural gas"
      71 "Mining of iron ores"
      72 "Mining of non-ferrous metal ores"
      81 "Quarrying of stone, sand and clay"
      89 "Mining and quarrying n.e.c."
      91 "Support activities for petroleum and natural gas mining"
      99 "Support activities for other mining and quarrying"
      101 "Processing and preserving of meat "
      102 "Processing and preserving of fish, crustaceans and molluscs "
      103 "Processing and preserving of fruit and vegetables "
      104 "Manufacture of vegetable and animal oils and fats "
      105 "Manufacture of dairy products "
      106 "Manufacture of grain mill products, starches and starch products "
      107 "Manufacture of other food products "
      108 "Manufacture of prepared animal feeds "
      110 "Manufacture of beverages "
      120 "Manufacture of tobacco products"
      131 "Spinning, weaving and finishing of textiles"
      139 "Manufacture of other textiles"
      141 "Manufacture of wearing apparel, except fur apparel "
      142 "Manufacture of articles of fur "
      143 "Manufacture of knitted and crocheted apparel "
      151 "Tanning and dressing of leather; manufacture of luggage, handbags, saddlery and harness; dressing and dyeing of fur "
      152 "Manufacture of footwear "
      161 "Sawmilling and planing of wood "
      162 "Manufacture of products of wood, cork, straw and plaiting materials "
      170 "Manufacture of paper and paper products "
      181 "Printing and service activities related to printing "
      182 "Reproduction of recorded media "
      191 "Manufacture of coke oven products "
      192 "Manufacture of refined petroleum products "
      201 "Manufacture of basic chemicals, fertilizer and nitrogen compounds, plastics and synthetic rubber in primary forms "
      202 "Manufacture of other chemical products "
      203 "Manufacture of man-made fibres "
      210 "Manufacture of pharmaceuticals, medicinal chemical and botanical products "
      221 "Manufacture of rubber products "
      222 "Manufacture of plastics products "
      231 "Manufacture of glass and glass products "
      239 "Manufacture of non-metallic mineral products n.e.c. "
      241 "Manufacture of basic iron and steel "
      242 "Manufacture of basic precious and other non-ferrous metals "
      243 "Casting of metals "
      251 "Manufacture of structural metal products, tanks, reservoirs and steam generators "
      252 "Manufacture of weapons and ammunition "
      259 "Manufacture of other fabricated metal products; metalworking service activities "
      261 "Manufacture of electronic components "
      262 "Manufacture of computers and peripheral equipment "
      263 "Manufacture of communication equipment "
      264 "Manufacture of consumer electronics "
      265 "Manufacture of measuring, testing, navigating and control equipment; watches and clocks "
      266 "Manufacture of irradiation, electromedical and electrotherapeutic equipment "
      267 "Manufacture of optical instruments and equipment "
      268 "Manufacture of magnetic and optical media "
      271 "Manufacture of electric motors, generators, transformers and electricity distribution and control apparatus "
      272 "Manufacture of batteries and accumulators "
      273 "Manufacture of wiring and wiring devices "
      274 "Manufacture of electric lighting equipment "
      275 "Manufacture of domestic appliances "
      279 "Manufacture of other electrical equipment "
      281 "Manufacture of general purpose machinery "
      282 "Manufacture of special-purpose machinery "
      291 "Manufacture of motor vehicles "
      292 "Manufacture of bodies (coachwork) for motor vehicles; manufacture of trailers and semi-trailers "
      293 "Manufacture of parts and accessories for motor vehicles "
      301 "Building of ships and boats "
      302 "Manufacture of railway locomotives and rolling stock "
      303 "Manufacture of air and spacecraft and related machinery "
      304 "Manufacture of military fighting vehicles "
      309 "Manufacture of transport equipment n.e.c. "
      310 "Manufacture of furniture "
      321 "Manufacture of jewellery, bijouterie and related articles "
      322 "Manufacture of musical instruments "
      323 "Manufacture of sports goods "
      324 "Manufacture of games and toys "
      325 "Manufacture of medical and dental instruments and supplies "
      329 "Other manufacturing n.e.c. "
      331 "Repair of fabricated metal products, machinery and equipment "
      332 "Installation of industrial machinery and equipment "
      351 "Electric power generation, transmission and distribution "
      352 "Manufacture of gas; distribution of gaseous fuels through mains "
      353 "Steam and air conditioning supply "
      360 "Water collection, treatment and supply "
      370 "Sewerage "
      381 "Waste collection "
      382 "Waste treatment and disposal "
      383 "Materials recovery "
      390 "Remediation activities and other waste management services "
      410 "Construction of buildings "
      421 "Construction of roads and railways "
      422 "Construction of utility projects "
      429 "Construction of other civil engineering projects "
      431 "Demolition and site preparation "
      432 "Electrical, plumbing and other construction installation activities "
      433 "Building completion and finishing "
      439 "Other specialized construction activities "
      451 "Sale of motor vehicles "
      452 "Maintenance and repair of motor vehicles "
      453 "Sale of motor vehicle parts and accessories "
      454 "Sale, maintenance and repair of motorcycles and related parts and accessories "
      461 "Wholesale on a fee or contract basis "
      462 "Wholesale of agricultural raw materials and live animals "
      463 "Wholesale of food, beverages and tobacco "
      464 "Wholesale of household goods "
      465 "Wholesale of machinery, equipment and supplies "
      466 "Other specialized wholesale "
      469 "Non-specialized wholesale trade "
      471 "Retail sale in non-specialized stores "
      472 "Retail sale of food, beverages and tobacco in specialized stores "
      473 "Retail sale of automotive fuel in specialized stores "
      474 "Retail sale of information and communications equipment in specialized stores "
      475 "Retail sale of other household equipment in specialized stores "
      476 "Retail sale of cultural and recreation goods in specialized stores "
      477 "Retail sale of other goods in specialized stores "
      478 "Retail sale via stalls and markets "
      479 "Retail trade not in stores, stalls or markets "
      491 "Transport via railways "
      492 "Other land transport "
      493 "Transport via pipeline "
      501 "Sea and coastal water transport "
      502 "Inland water transport "
      511 "Passenger air transport "
      512 "Freight air transport "
      521 "Warehousing and storage "
      522 "Support activities for transportation "
      531 "Postal activities "
      532 "Courier activities "
      551 "Short term accommodation activities "
      552 "Camping grounds, recreational vehicle parks and trailer parks "
      559 "Other accommodation "
      561 "Restaurants and mobile food service activities "
      562 "Event catering and other food service activities "
      563 "Beverage serving activities "
      581 "Publishing of books, periodicals and other publishing activities "
      582 "Software publishing "
      591 "Motion picture, video and television programme activities "
      592 "Sound recording and music publishing activities "
      601 "Radio broadcasting "
      602 "Television programming and broadcasting activities "
      611 "Wired telecommunications activities "
      612 "Wireless telecommunications activities "
      613 "Satellite telecommunications activities "
      619 "Other telecommunications activities "
      620 "Computer programming, consultancy and related activities "
      631 "Data processing, hosting and related activities; web portals "
      639 "Other information service activities "
      641 "Monetary intermediation "
      642 "Activities of holding companies "
      643 "Trusts, funds and other financial vehicles "
      649 "Other financial service activities, except insurance and pension funding activities "
      651 "Insurance "
      652 "Reinsurance "
      653 "Pension funding "
      661 "Activities auxiliary to financial service activities, except insurance and pension funding "
      662 "Activities auxiliary to insurance and pension funding "
      663 "Fund management activities "
      681 "Real estate activities with own or leased property "
      682 "Real estate activities on a fee or contract basis "
      691 "Legal activities "
      692 "Accounting, bookkeeping and auditing activities; tax consultancy "
      701 "Activities of head offices "
      702 "Management consultancy activities "
      711 "Architectural and engineering activities and related technical consultancy "
      712 "Technical testing and analysis "
      721 "Research and experimental development on natural sciences and engineering "
      722 "Research and experimental development on social sciences and humanities "
      731 "Advertising "
      732 "Market research and public opinion polling "
      741 "Specialized design activities "
      742 "Photographic activities "
      749 "Other professional, scientific and technical activities n.e.c. "
      750 " Veterinary activities "
      771 "Renting and leasing of motor vehicles "
      772 "Renting and leasing of personal and household goods "
      773 "Renting and leasing of other machinery, equipment and tangible goods n.e.c. "
      774 "Leasing of nonfinancial intangible assets "
      781 "Activities of employment placement agencies "
      782 "Temporary employment agency activities "
      783 "Human resources provision and management of human resources functions "
      791 "Travel agency and tour operator activities "
      799 "Other reservation service activities "
      801 "Private security activities "
      802 "Security systems service activities "
      803 "Investigation activities "
      811 "Combined facilities support activities "
      812 "Cleaning activities "
      813 "Landscape care and maintenance service activities "
      821 "Office administrative and support activities "
      822 "Activities of call centres "
      823 "Organization of conventions and trade shows "
      829 "Business support service activities n.e.c. "
      841 "Administration of the State and the economic and social policy of the community "
      842 "Provision of services to the community as a whole "
      843 "Compulsory social security activities "
      851 "Primary education "
      852 "Secondary education "
      853 "Higher education "
      854 "Other education "
      855 "Educational support services"
      861 "Hospital activities"
      862 "Medical and dental practice activities"
      869 "Other human health activities"
      871 "Nursing care facilities"
      872 "Residential care activities for mental retardation, mental health and substance abuse"
      873 "Residential care activities for the elderly and disabled"
      879 "Other residential care activities n.e.c."
      881 "Social work activities without accommodation for the elderly and disabled"
      889 "Other social work activities without accommodation n.e.c."
      900 "Creative, arts and entertainment activities"
      910 "Libraries, archives, museums and other cultural activities"
      920 "Gambling and betting activities"
      931 "Sports activities"
      932 "Other amusement and recreation activities"
      941 "Activities of business, employers and professional membership organizations"
      942 "Activities of trade unions"
      949 "Activities of other membership organizations"
      951 "Repair of computers and communication equipment"
      952 "Repair of personal and household goods"
      960 "Other personal service activities"
      970 "Activities of households as employers of domestic personnel"
      981 "Undifferentiated goods-producing activities of private households for own use"
      982 "Undifferentiated service-producing activities of private households for own use"
      990 "Activities of extraterritorial organizations and bodies" ;
      #delimit cr
      la values ind_3dig_p ind_3dig_label

      Best,

      Comment


      • #4
        Your problem is that you have not run the full code you show in post #3 all at once. You have it in your Do-file editor window, but you first select and run the #delimit command, and then select and run some or all of the label define command. Here's what happens when I do the same.
        Code:
        . do "/var/folders/xr/lm5ccr996k7dspxs35yqzyt80000gp/T//SD16690.000000"
        
        . #delimit ;
        delimiter now ;
        .
        end of do-file
        
        . do "/var/folders/xr/lm5ccr996k7dspxs35yqzyt80000gp/T//SD16690.000000"
        
        . label define ind_3dig_label 11 "Growing of non-perennial crops"
        
        . 12 "Growing of perennial crops"
        12 is not a valid command name
        r(199);
        
        end of do-file
        
        r(199);
        
        .
        Do you notice that the selected lines are copied into a temporary do-file and that do-file is run? The #delimit command is limited to the do-file within which it is run. When that do-file ends, the delimiter is returned to its prior state. So when the label define command is run, the delimiter is back to being the cr; the label define is not continued to a new line (note that in the listing the next line is preceded by the command prompt of ". " rather than the usual continuation indicator of "> ") and the 12 is taken as a command name.

        Comment


        • #5
          Hi Kumar
          If I run the whole block of code that you provide, i have no problems. Perhaps the problem you are finding is because you are running only pieces of the code every time.

          Comment


          • #6
            Hi William,

            Thanks for pointing that out - that's correct and helpful to know.

            I have also tried running the full code at once though, including the delimit command. In that case, I get the "invalid syntax" error message (not the "12 is not a valid command one"). Does the full code run for you?

            Best,

            Comment


            • #7
              This works for me.

              Code:
              . clear all
              
              . set obs 1
              number of observations (_N) was 0, now 1
              
              . generate ind_3dig_p = 13
              (1 missing value generated)
              
              . #delimit ; 
              delimiter now ;
              . label define ind_3dig_label 11 "Growing of non-perennial crops"
              > 12 "Growing of perennial crops"
              > 13 "Plant propagation"
              ...
              > 982 "Undifferentiated service-producing activities of private households for own use"
              > 990 "Activities of extraterritorial organizations and bodies" ;
              
              . #delimit cr
              delimiter now cr
              . la values ind_3dig_p ind_3dig_label
              
              . list
              
                   +-------------------+
                   |        ind_3dig_p |
                   |-------------------|
                1. | Plant propagation |
                   +-------------------+
              
              .

              Comment

              Working...
              X