Announcement

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

  • split a variable

    Good evening
    I use stata 14 and I have a variable that groups the different equipments that the household has. The household can have one or more equipments and the information is summarized by the variable c1.
    I would like to break this variable c1 to have the frequency of each equipment.
    thank you

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str55 c1
    "Moulin à mil"                      
    "Moulin à mil, Decortiqueuse à mil"
    "Moulin à mil"                      
    "Moulin à mil"                      
    "Batteuse à mil"                    
    "Décortiqueuse riz"                 
    "Moulin à mil"                      
    "Moulin à mil, Decortiqueuse à mil"
    "Décortiqueuse riz, Batteuse à riz"
    "Moulin à mil, Decortiqueuse à mil"
    "Moulin à mil"                      
    "Moulin à mil"                      
    "Moulin à mil, Decortiqueuse à mil"
    "Moulin à mil, Decortiqueuse à mil"
    "Moulin à mil"                      
    "Moulin à mil, Decortiqueuse à mil"
    "Moulin à mil"                      
    "Moulin à mil, Broy. arachide"      
    "Moulin à mil, Decortiqueuse à mil"
    "Presse à huile"                    
    end

  • #2
    Code:
    preserve
    split c1, gen(item) parse(",")
    gen long obs_no = _n
    reshape long item, i(obs_no)
    tab item
    restore
    Note: This code assumes that the separate items in any observation of c1 are separated by commas, and that no item itself contains an embedded comma.
    Last edited by Clyde Schechter; 06 Apr 2022, 17:08.

    Comment


    • #3
      Thank you very much Clyde

      Comment

      Working...
      X