Announcement

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

  • How to import multi-section option from excel to Stata

    Hi!
    I have a question in terms of import data from excel to Stata.
    Say if one of the column in my excel sheet is a drop down list with multi-selection options.
    For example, the information in such column can be something like "one,two or one,two,three,four"..
    How can I separate such information in Stata for analysis purpose?
    Willing to hear the thoughts. Thank You!

  • #2
    Well, it doesn't matter that it originates in Excel. Once imported to Stata you have, I presume, a string variable with values like "one, two" or "one, two, three, four." The -split- command will break this up into separate variables for each response.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str21 var1
    "one, two"             
    "three, two, one"      
    "one, two, three, four"
    end
    
    list, clean
    split var1, parse(", ") gen(new_var)
    list, clean
    In the future, when asking for help with code, please post example data, using the -dataex- command. If you are running version 15.1 or a fully updated version 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    When asking for help with code, always show example data. When showing example data, always use -dataex-.

    Comment

    Working...
    X