Announcement

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

  • Generating a variable from other variables

    Dear all, I would very much appreciate your support for the following:

    I need to generate a dummy variable named "Respondent 1" and another named "Respondent 2".

    I have variables for which information was collected only for first respondents (for example. Gender R1, or Name R1, Ethnicity R1) or and other variables for which information is collected only for second respondents (for example. Gender R2, or Name R2, Ethnicity R2).

    I need a command that allows me to generate my dummy variables from the variables I have.

    For example, saying that Respondent 1==1 if the respondent has any value on variable GenderR1 and one saying that Respondent2==1 if the respondent has any value on variable GenderR2.

    How can I do that?

    Thank you very much in advance for your support.

  • #2
    I would also like to create a variable called "RESPONDENT NO." and have 1 and 2 as the possible responses.

    Thanks again.

    Comment


    • #3
      hey,

      - this might be handy:
      " As we will see shortly, in most cases, if you use factor-variable notation, you do not need to create dummy variables.

      In cases where factor variables are not the answer, you may use generate to create one dummy variable at a time and tabulate to create a set of dummies at once"

      https://www.stata.com/support/faqs/d...mmy-variables/


      - here is a example in stata
      https://www.youtube.com/watch?v=KdfPar9YoHs


      - also please note that users might be better able to help you out if you are to include a sample of your data;

      using
      dataex

      Comment


      • #4
        Thank you very much.

        I really just need to know the syntax for telling stata "any value" in a variable. Meaning Generate variable RespondentNo==1 if anyvalue in variable GenderR1

        Comment


        • #5
          it is not at all clear how your data are set up (please read the FAQ and follow its advice); here is a guess:
          Code:
          gen byte RespondentNo=1 if GenderR1<.
          however, this will give you a value of missing (not 0) if GenderR1 is missing; instead, try this:
          Code:
          gen byte RespondentNo=GenderR1<.
          note also that you used double equals sign and I have changed that as this is an assignment not a logic check

          Comment


          • #6
            "Any value" is equivalent, I assume, to "not missing".
            Code:
            recode GenderR1 (nonmiss==1) (miss=0), gen(Respondent1)
            recode GenderR2 (nonmiss==1) (miss=0), gen(Respondent2)
            Stata/MP 14.1 (64-bit x86-64)
            Revision 19 May 2016
            Win 8.1

            Comment


            • #7
              Thank you. I saw the video and read the FAQ, but can't solve the issue.

              I have a list of variables for which information is only relative to Respondents number 1. For example: GenderR1 = 1 if male and =2 if female.

              I than have other variables for which information is only relative to Respondents number 2. For example: GenderR2= 1 if male and 2 if female.

              I need to create a variable named RESPONDENTS No. that equals 1 for First Respondents and 2 for Second Respondents. and I need to do so using the data I have - hence, telling STATA to generate RespondentsNO=1 if there is any response in Gender1 and RespondentsNo=2 if there is any response in Gender2.

              I hope that is clearer.

              Thank you for your help.

              Comment


              • #8
                Just saw #2

                Rich's solution should get you started. Alternatively:

                Code:
                gen RespondentNo=.
                replace RespondentNo=1 if !mi(GenderR1)
                replace RespondentNo=2 if !mi(GenderR2)
                Last edited by Carole J. Wilson; 29 Aug 2018, 07:10.
                Stata/MP 14.1 (64-bit x86-64)
                Revision 19 May 2016
                Win 8.1

                Comment


                • #9
                  Yes, apologies. I figured that having one variable coded 1 and 2 is best.

                  Your input above is helping me work towards that though - so thank you. If you have further suggestions, I thank you in advance.

                  Comment


                  • #10
                    See my edited post in #8. I missed #2.
                    Stata/MP 14.1 (64-bit x86-64)
                    Revision 19 May 2016
                    Win 8.1

                    Comment


                    • #11
                      Thank you very much. It worked and I understood the way of thinking in order to structure the syntax. I appreciate it.

                      Comment

                      Working...
                      X