Dear All,

I am using firm-level data to gather information on the number of products produced within an industry. The data excerpt is as follows:
Company Name Product/Raw Material name
3 F Industries Ltd. ACID OILS
CHOCOLATE
CRUDE OILS
DEOILED CAKES
EDIBLE OILS
EXPELLER OIL CAKES
EXPELLER OILS
F C GLYCERINE
FATTY ACIDS & GLYCERINE
FLOUR MILL
MAIZE
OTHER ITEMS
PALM FFB
PALM NUTS
PITCH OILS
POWER
RAW OILS
REFINED OIL
REFINED WAX,VEGETABLE WAX
RICE
S F OLEINS
S F STEARINS
STEARIC ACID/ HARD OILS
VANASPATI
VEGETABLE OILS
3D Technopack Pvt. Ltd. SEAMLESS PLASTIC TUBES
3M India Ltd. ABRASIVE
EPOXY RESIN
INCOME FROM CONTRACT RESEARCH
INTEREST
OTHERS
OTHERS (TRADED)
PAINT POLISHES
PAPER & PAPER TAPE
SALE OF SCRAP
SELF ADHESIVE LABLES
SURGICAL & DENTAL PRODUCTS
A B B India Ltd. COMMISSION
ELECTRONIC CONTROL & SUPPLY UNITS
ERECTION & OTHER SERVICES
GAS ANALYSERS & SYSTEMS
MINI-COMPUTER/MICROPROCESSOR BASED SYSTEMS
MOTORS/ALTERNATORS/GENERATORS UPTO 20 MW
MULTIPLEXURES
OTHERS
PLCC EQUIPMENT
POWER CAPACITORS
POWER TRANSFORMERS
PROCESS CONTROL INSTRUMENTS
PROJECT ITEMS
ROBOTICS
SCRAP
SWITCHGEARS OF ALL TYPES
TELEMETERING EQUIPMENT
TURBOCHARGERS
In the above table, 3F Industries Ltd. and 3D technopack pvt. ltd. produce 25 and 1 product respectively. Is it possible to count string entries in a column based on groups?
The original bysort command, i.e., bysort companyname: egen products=count(productrawmaterialname) does not work. Is there a way where I can generate unique ids for each company and then use bysort? When I use gen id=_n, stata asks me to sort company name, which does not serve the purpose. Please help.