Announcement

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

  • Problem with Counting observations across firm identifier

    Dear Stata users,
    Version 16.1

    I have 4 variables - firm_id, type_product, type_airframe, and Application of each product.
    Each firm can have 1 product or multiple products (firm 1 has 9 types of products). Each product can have 3 different types of the airframe, and can have multiple applications.

    * I have 2 questions -
    1. how can i create a variable "count" that shows different types of airframes sold by each firm. I have shown a count variable in the sample data
    2. How can I create a variable "total_apps" that counts different applications (no repetition) across all the products per firm? OR
    How many unique applications are there per firm_id?

    I tried to split the variable Application using code
    -
    split Application, p( "its a semicolon in the parenthesis"

    Got stuck after that. Please see the example using dataex below.

    Thanks
    ***



    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(firm_id type_product) long type_airframe float count str428 Application
    1 1 1 2 "Disaster Response; Environmental Research or Monitoring; Firefighting; Hobby; Imaging; Inspection; Mining; Precision Agriculture; Research; Search & Rescue; Survey, Mapping"                                              
    1 2 2 2 "Education; Environmental Research or Monitoring; Hobby; Imaging; Inspection; Research"                                                                                                                                     
    1 3 2 2 "Disaster Response; Environmental Research or Monitoring; Hobby; Imaging; Inspection; Precision Agriculture; Research; Search & Rescue; Survey, Mapping"                                                                    
    1 4 2 2 "Environmental Research or Monitoring; Hobby; Imaging; Inspection; Precision Agriculture; Survey, Mapping"                                                                                                                  
    1 5 2 2 "Cable Services; Disaster Response; Environmental Research or Monitoring; Hobby; Imaging; Inspection; Mining; Precision Agriculture; Search & Rescue; Survey, Mapping"                                                      
    1 6 2 2 "Disaster Response; Environmental Research or Monitoring; Hobby; Imaging; Inspection; Precision Agriculture; Research; Survey, Mapping"                                                                                     
    1 7 2 2 "Cable Services; Disaster Response; Environmental Research or Monitoring; Hobby; Imaging; Inspection; Intelligence, Surveillance, Reconnaissance; Patrol, Security; Precision Agriculture; Search & Rescue; Survey, Mapping"
    1 8 2 2 "Cable Services; Disaster Response; Environmental Research or Monitoring; Imaging; Inspection; Mining; Precision Agriculture; Survey, Mapping"                                                                              
    1 9 2 2 "Cable Services; Imaging; Inspection; Mining; Pipeline Services; Precision Agriculture; Survey, Mapping"                                                                                                                    
    2 1 1 1 "Disaster Response; Environmental Research or Monitoring; Imaging; Intelligence, Surveillance, Reconnaissance; Patrol, Security; Prototype; Research; Survey, Mapping"                                                      
    3 1 2 1 "Cable Services; Imaging; Inspection; Intelligence, Surveillance, Reconnaissance; Patrol, Security; Pipeline Services; Precision Agriculture; Search & Rescue"                                                              
    4 1 1 3 "Imaging; Intelligence, Surveillance, Reconnaissance; Patrol, Security; Target Acquisition"                                                                                                                                 
    4 2 3 3 "Communications; Disaster Response; Imaging; Intelligence, Surveillance, Reconnaissance; Patrol, Security; Search & Rescue; Survey, Mapping"                                                                                
    4 3 2 3 "Attack, Weapons Delivery; Communications; Imaging; Inspection; Intelligence, Surveillance, Reconnaissance; Logistics; Patrol, Security; Target Acquisition"                                                                
    4 4 2 3 "Disaster Response; Firefighting; Imaging; Inspection; Intelligence, Surveillance, Reconnaissance; Observation; Patrol, Security; Search & Rescue; Target Acquisition"                                                      
    4 5 3 3 "Communications; Disaster Response; Imaging; Intelligence, Surveillance, Reconnaissance; Patrol, Security; Search & Rescue; Survey, Mapping; Target Acquisition"                                                            
    4 6 1 3 "Attack, Weapons Delivery; Target Acquisition"                                                                                                                                                                              
    end
    label values type_airframe airframe1

  • #2
    https://www.stata-journal.com/sjpdf....iclenum=dm0042 gives a discussion of counting distinct values (including a riff on why that is a much better word than unique)

    But if semi-colons are separators then the number of categories will be the number of semi-colons PLUS 1, as you tell us there are no repetitions.

    Code:
    gen n_cat = length(Application) - length(subinstr(Application, ";", "", .)) + 1

    See https://journals.sagepub.com/doi/pdf...867X1101100212
    Last edited by Nick Cox; 09 Mar 2020, 05:36.

    Comment


    • #3
      Thank You, Nick.

      Comment

      Working...
      X