Announcement

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

  • Splitting a data file based on one variable

    Hi, I have a data file with assessments of children by two groups of staff (CHW and Physician). There is a variable in my data file for every assessment which indicate the staff who assessed the child (CHW/Physician). Now I want to make two different files for two group of assessors (CHW and Physician) keeping all other variables in the data file same. How can I do it in STATA?

    Thanks in advance.

  • #2
    You show no example data, so I will give you code that may require adaptation to your actual data. This code assumes that the variable that distinguishes the two staff groups is named assessor and that it is a string variable. If that is not the case, you will have to modify the code accordingly.

    Code:
    use if assessor == "CHW" using original_data_set, clear
    drop assessor
    save assessed_by_CHW, replace
    use if assessor == "Physician" using original_data_set, clear
    drop assessor
    save assessed_by_Physician, replace
    In the future, when asking for help with code, please use the -dataex- command and show example data. Although sometimes, as here, it is possible to give an answer that has a reasonable probability of being correct, this is usually not the case. Moreover, such answers are necessarily based on experience-based guesses or intuitions about the nature of your data. When those guesses are wrong, both you and the person trying to help you have wasted their time as you end up with useless code. To avoid this, a -dataex- based example provides all of the information needed to develop and test a solution.

    In the future, when showing data examples, please use the -dataex- command to do so. If you are running version 18, 17, 16 or a fully updated version 15.1 or 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.

    Comment


    • #3
      Thanks a lot for sharing the codes and your guidance.

      Comment

      Working...
      X