Announcement

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

  • Collapse command

    Hello

    In my dataset, I have two string variables. I am trying to summarize the number of implementscheme by districts.
    implementscheme district
    PumpSet State Plan Araria
    Rotavator State Plan Patna
    Folding LDPE Irrigation Pipe State Plan Arwal
    IrrigationPipe NFSM Arwal
    I am using collapse (count) implementscheme, by(district). I get type mismatch error.
    Am I right in using collapse command? or some other command helps here?

    Thank You
    Smriti

  • #2
    Your data example is difficult to read -- in any future question do please follow http://www.statalist.org/forums/help#stata and use dataex for a readable, unambiguous example -- but the problem is clear enough.

    count as astatistic in collapsecounts non-missing values and only applies to numeric variables. Even if string variables were allowed, it would not be what you want, e.g. the count of non-missing values in "a" "a" "a" "b" "b" "c" is 0, as no value is missing. Hence collapse could not possibly give you the data structure you seek, even with an encode of the string variable.

    If you want a new dataset, then

    Code:
    contract implementscheme district
    should work, while a tabulation is given by

    Code:
    tabulate district  implementscheme
    where I am guessing that you have more districts than schemes, hence district is better on the rows.

    Comment


    • #3
      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input str86 implementscheme str18 district
      "Animal Deterrent Bio-Acaustic Equipment-Electric Operated(With Solar Panel) State Plan" "Madhubani"        
      "Animal Deterrent Bio-Acaustic Equipment-Electric Operated(With Solar Panel) State Plan" "Nalanda"          
      "Animal Deterrent Bio-Acaustic Equipment-Electric Operated(With Solar Panel) State Plan" "Sheohar"          
      "Animal Deterrent Bio-Acaustic Equipment-Electric Operated(With Solar Panel) State Plan" "Vaishali"         
      "Brush Cutter(1 HP & above petrol engine operated) State Plan"                           "Arwal"            
      "Brush Cutter(1 HP & above petrol engine operated) State Plan"                           "Begusarai"        
      "Brush Cutter(1 HP & above petrol engine operated) State Plan"                           "Bhagalpur"        
      "Brush Cutter(1 HP & above petrol engine operated) State Plan"                           "Madhepura"        
      "Brush Cutter(1 HP & above petrol engine operated) State Plan"                           "Madhubani"        
      "Brush Cutter(1 HP & above petrol engine operated) State Plan"                           "Munger"           
      "Brush Cutter(1 HP & above petrol engine operated) State Plan"                           "Muzaffarpur"      
      "Brush Cutter(1 HP & above petrol engine operated) State Plan"                           "Nalanda"          
      "Brush Cutter(1 HP & above petrol engine operated) State Plan"                           "Pashchim Champaran"
      "Brush Cutter(1 HP & above petrol engine operated) State Plan"                           "Patna"            
      "Brush Cutter(1 HP & above petrol engine operated) State Plan"                           "Purbi Champaran"  
      "Brush Cutter(1 HP & above petrol engine operated) State Plan"                           "Saharsa"          
      "Brush Cutter(1 HP & above petrol engine operated) State Plan"                           "Samastipur"       
      "Brush Cutter(1 HP & above petrol engine operated) State Plan"                           "Saran"            
      "Brush Cutter(1 HP & above petrol engine operated) State Plan"                           "Sheohar"          
      "Brush Cutter(1 HP & above petrol engine operated) State Plan"                           "Supaul"           
      "Brush Cutter(Below 3 BHP petrol driven) State Plan"                                     "Begusarai"        
      "Brush Cutter(Below 3 BHP petrol driven) State Plan"                                     "Bhagalpur"        
      "Brush Cutter(Below 3 BHP petrol driven) State Plan"                                     "Khagaria"         
      "Brush Cutter(Below 3 BHP petrol driven) State Plan"                                     "Madhepura"        
      "Brush Cutter(Below 3 BHP petrol driven) State Plan"                                     "Pashchim Champaran"
      "Brush Cutter(Below 3 BHP petrol driven) State Plan"                                     "Saharsa"          
      "Brush Cutter(Below 3 BHP petrol driven) State Plan"                                     "Sheohar"          
      "Cage Wheel(one pair) State Plan"                                                        "Banka"            
      "Cage Wheel(one pair) State Plan"                                                        "Nalanda"          
      "Cage Wheel(one pair) State Plan"                                                        "Patna"            
      "Cage Wheel(one pair) State Plan"                                                        "Saharsa"          
      "Cage Wheel(one pair) State Plan"                                                        "Sheikhpura"       
      "Cage Wheel(one pair) State Plan"                                                        "Supaul"           
      "Chaff Cutter Manual State Plan"                                                         "Araria"           
      "Chaff Cutter Manual State Plan"                                                         "Arwal"            
      "Chaff Cutter Manual State Plan"                                                         "Aurangabad"       
      "Chaff Cutter Manual State Plan"                                                         "Banka"            
      "Chaff Cutter Manual State Plan"                                                         "Begusarai"        
      "Chaff Cutter Manual State Plan"                                                         "Bhagalpur"        
      "Chaff Cutter Manual State Plan"                                                         "Bhojpur"          
      "Chaff Cutter Manual State Plan"                                                         "Buxar"            
      "Chaff Cutter Manual State Plan"                                                         "Darbhanga"        
      "Chaff Cutter Manual State Plan"                                                         "Gaya"             
      "Chaff Cutter Manual State Plan"                                                         "Gopalganj"        
      "Chaff Cutter Manual State Plan"                                                         "Jamui"            
      "Chaff Cutter Manual State Plan"                                                         "Jehanabad"        
      "Chaff Cutter Manual State Plan"                                                         "Kaimur (Bhabua)"  
      "Chaff Cutter Manual State Plan"                                                         "Katihar"          
      "Chaff Cutter Manual State Plan"                                                         "Khagaria"         
      "Chaff Cutter Manual State Plan"                                                         "Kishanganj"       
      "Chaff Cutter Manual State Plan"                                                         "Lakhisarai"       
      "Chaff Cutter Manual State Plan"                                                         "Madhepura"        
      "Chaff Cutter Manual State Plan"                                                         "Madhubani"        
      "Chaff Cutter Manual State Plan"                                                         "Munger"           
      "Chaff Cutter Manual State Plan"                                                         "Muzaffarpur"      
      "Chaff Cutter Manual State Plan"                                                         "Nalanda"          
      "Chaff Cutter Manual State Plan"                                                         "Nawada"           
      "Chaff Cutter Manual State Plan"                                                         "Pashchim Champaran"
      "Chaff Cutter Manual State Plan"                                                         "Patna"            
      "Chaff Cutter Manual State Plan"                                                         "Purbi Champaran"  
      "Chaff Cutter Manual State Plan"                                                         "Purnia"           
      "Chaff Cutter Manual State Plan"                                                         "Rohtas"           
      "Chaff Cutter Manual State Plan"                                                         "Saharsa"          
      "Chaff Cutter Manual State Plan"                                                         "Samastipur"       
      "Chaff Cutter Manual State Plan"                                                         "Saran"            
      "Chaff Cutter Manual State Plan"                                                         "Sheikhpura"       
      "Chaff Cutter Manual State Plan"                                                         "Sheohar"          
      "Chaff Cutter Manual State Plan"                                                         "Sitamarhi"        
      "Chaff Cutter Manual State Plan"                                                         "Siwan"            
      "Chaff Cutter Manual State Plan"                                                         "Supaul"           
      "Chaff Cutter Manual State Plan"                                                         "Vaishali"         
      "Chaff Cutter(Mannual Heavy Duty)-3 Roller, Shuking Type State Plan"                     "Araria"           
      "Chaff Cutter(Mannual Heavy Duty)-3 Roller, Shuking Type State Plan"                     "Arwal"            
      "Chaff Cutter(Mannual Heavy Duty)-3 Roller, Shuking Type State Plan"                     "Banka"            
      "Chaff Cutter(Mannual Heavy Duty)-3 Roller, Shuking Type State Plan"                     "Begusarai"        
      "Chaff Cutter(Mannual Heavy Duty)-3 Roller, Shuking Type State Plan"                     "Bhagalpur"        
      "Chaff Cutter(Mannual Heavy Duty)-3 Roller, Shuking Type State Plan"                     "Gaya"             
      "Chaff Cutter(Mannual Heavy Duty)-3 Roller, Shuking Type State Plan"                     "Gopalganj"        
      "Chaff Cutter(Mannual Heavy Duty)-3 Roller, Shuking Type State Plan"                     "Jamui"            
      "Chaff Cutter(Mannual Heavy Duty)-3 Roller, Shuking Type State Plan"                     "Kaimur (Bhabua)"  
      "Chaff Cutter(Mannual Heavy Duty)-3 Roller, Shuking Type State Plan"                     "Khagaria"         
      "Chaff Cutter(Mannual Heavy Duty)-3 Roller, Shuking Type State Plan"                     "Lakhisarai"       
      "Chaff Cutter(Mannual Heavy Duty)-3 Roller, Shuking Type State Plan"                     "Madhepura"        
      "Chaff Cutter(Mannual Heavy Duty)-3 Roller, Shuking Type State Plan"                     "Madhubani"        
      "Chaff Cutter(Mannual Heavy Duty)-3 Roller, Shuking Type State Plan"                     "Munger"           
      "Chaff Cutter(Mannual Heavy Duty)-3 Roller, Shuking Type State Plan"                     "Muzaffarpur"      
      "Chaff Cutter(Mannual Heavy Duty)-3 Roller, Shuking Type State Plan"                     "Nalanda"          
      "Chaff Cutter(Mannual Heavy Duty)-3 Roller, Shuking Type State Plan"                     "Pashchim Champaran"
      "Chaff Cutter(Mannual Heavy Duty)-3 Roller, Shuking Type State Plan"                     "Patna"            
      "Chaff Cutter(Mannual Heavy Duty)-3 Roller, Shuking Type State Plan"                     "Purbi Champaran"  
      "Chaff Cutter(Mannual Heavy Duty)-3 Roller, Shuking Type State Plan"                     "Purnia"           
      "Chaff Cutter(Mannual Heavy Duty)-3 Roller, Shuking Type State Plan"                     "Saharsa"          
      "Chaff Cutter(Mannual Heavy Duty)-3 Roller, Shuking Type State Plan"                     "Samastipur"       
      "Chaff Cutter(Mannual Heavy Duty)-3 Roller, Shuking Type State Plan"                     "Saran"            
      "Chaff Cutter(Mannual Heavy Duty)-3 Roller, Shuking Type State Plan"                     "Sheikhpura"       
      "Chaff Cutter(Mannual Heavy Duty)-3 Roller, Shuking Type State Plan"                     "Sheohar"          
      "Chaff Cutter(Mannual Heavy Duty)-3 Roller, Shuking Type State Plan"                     "Siwan"            
      "Chaff Cutter(Mannual Heavy Duty)-3 Roller, Shuking Type State Plan"                     "Supaul"           
      "Chaff Cutter(Manual)-2 Roller,Non-Shuking Type State Plan"                              "Araria"           
      "Chaff Cutter(Manual)-2 Roller,Non-Shuking Type State Plan"                              "Arwal"            
      end

      Comment


      • #4
        Hi Nick

        This is how the data looks. I was not trying to create a new dataset but was trying to understand the frequency of implementscheme by district.
        The contract command works perfectly. Tabulation can not since there are too many values.

        Thank You

        Comment


        • #5
          OK. In #2 I exaggerated in saying that

          collapse could not possibly give you the data structure you seek
          because this simple trick gets you counts:

          Code:
          gen count = 1 
          collapse (sum) count, by(implementscheme district)
          count is a poor name when its values are all 1, but once collapse has done its work, it is exactly right. There is no objection to string variables as arguments for by().

          Comment


          • #6
            Thank You. That worked.

            Comment

            Working...
            X