Announcement

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

  • Merging two observation types into one

    I'm a total stata newbie and I feel like I'm brain farting on how to do this but I'm trying to combine "Strongly disagree" and "Somewhat disagree" into one singular "Disagree". Any tips? Below is the tabulation of the data.

    Click image for larger version

Name:	Screenshot 2025-03-18 163536.jpg
Views:	1
Size:	18.6 KB
ID:	1774581


    I've been using
    Code:
    replace nataccess_factor = "Disagree" if nataccess_factor == "Strongly disagree" | nataccess_factor == "Somewhat disagree"
    and other variations of it on both the string and numeric versions but I keep getting r(109) type mismatch errors.

    I used
    Code:
    encode
    on the original string data because I'm trying to run a regression. So I could make changes on the numeric data or the original string data. Thanks in advance!

  • #2
    Update I figured it out but idk how to delete this post, pls ignore lol

    Comment


    • #3
      The Forum software does not support the deletion of posts. This was, I believe, a deliberate design choice. The Forum is not intended to be a dialog between a questioner and a responder. It is intended to be a community resource. It is likely that others will encounter a similar problem to yours in the future, and they may come here to look for an answer. Before posting, people often search the existing threads to see if it has already been answered. So if you have figured out the solution to your problem, the hope is that you would post back showing your solution so that others can learn from it.

      Comment


      • #4
        Clyde Schechter is as usual exactly right. Indeed, it's explicit in the FAQ Advice that all are asked to read before posting that you can't delete your posts.

        The main reason is -- as discussed here -- that many people take the line that now their question is solved, the post should be deleted, which is a misunderstanding of what the forum is all about. If you want private help, any number of outfits advertise on X.

        Or sometimes people don't want a track record of a question that in retrospect appears a little silly or stupid, but the forum exists for all kinds of questions, and it's not accidental either that a policy of no deletion may be an incentive not to ask a really lazy question.

        There is one exception worth flagging here. Sometimes people realise that they accidentally posted using data that should be confidential. In that case, contact the forum administrators through the CONTACT US button and they will arrange an edit.

        Comment


        • #5
          Back to the original question: Using a string variable has the unwanted side effect that the natural ordering is lost as without some other steer, tables and graphs will use alphabetical order. Assuming that the four categories are the only possible categories, then you should not only encode but also define suitable associations in advance, such as by

          Code:
          label def nataccess 1 "Strongly disagree" 2 "Somewhat disagree" 3 "Somewhat agree" 4 "Strongly agree" 
          encode nataccess_factor, gen(nataccess) label(nataccess)
          noting that the definitions need to change if there are extra categories, and more positively that the same set of value labels may be useful for other variables.

          Comment

          Working...
          X