Announcement

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

  • #16
    That calls for an extra if condition on every command, I imagine.

    Comment


    • #17

      Hello Nick ,my question is similar but in another sense I have the id reported by a single member and I would like to locate them by row in their respective id by rows. I HAVE THEM IN WIDE AND I WOULD LIKE TO PUT IT LONG.

      I would appreciate your comment, since I am new with STATA. I would like to locate them in their respective member since I have the id (member) ID (FAMILY)


      Thanks
      self report of high hypertension : 1( yes ) 0 ( no)
      id1, id2 = member family list
      report treatment = 1(yes) 0 ( no) same report treatment
      ID id self report of high hypertension id1 report treatment1 id2 report treatment2
      001 1 1 2 1 1 0
      001 2
      002 1 1 2 0 3 1
      002 2
      002 3
      003 1 0
      003 2
      003 3

      Comment


      • #18
        The tableau you show in lieu of an actual example of your data is a confusing melange of long and wide data and is not, in any case a possible Stata data set because it has illegal variable names and extraneous material. I attempted to reconstruct a data set that might be what you are actually starting with, but realized that the possibilities are ambiguous.

        You need to show an example of your actual data. Explanations and tables will not do the trick. Use the -dataex- command and show an excerpt of your actual Stata data. (If you don't actually have your data in Stata yet, then it is premature to ask for help with code.) If you are running version 15.1 or a fully updated version 14.2, it 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


        • #19
          Thank you Clyde, since I am new with this from STATA:

          What I am trying to do is: in my macro survey I have one member per family that informs the members of their house that they have hypertension (SH27), if they inform me that YES, inform the order (SH27O_ *) that they are the same as found in V003 (MEMBER ID INSIDE THE HOUSE) and the treatment report are (SH27T_ *) - may be some or all, finally what I want is to create a single variable that locates these treatment reports in hypertension (SH27T- new column or variable) in their respective household members (V003) by family (family HHID-Id)

          input int HHID byte V003 long SH27 byte SH27O_1 long SH27T_1 byte SH27O_2 long SH27T_2
          2003 1 . . . . .
          2003 2 1 . . . .
          2007 1 1 . . . .
          2011 1 1 . . . .
          2011 2 . . . . .
          2011 3 . . . . .
          2015 1 . . . . .
          2015 2 2 2 1 . .
          2015 3 . . . . .
          2015 4 . . . . .
          2019 1 . . . . .
          2019 2 1 . . . .
          2019 3 . . . . .
          2019 4 . . . . .
          2019 5 . . . . .
          2023 1 1 . . . .
          2028 1 . . . . .
          2028 2 2 1 2 2 1
          2032 1 1 . . . .
          2036 1 . . . . .
          2036 2 1 . . . .
          2040 1 1 . . . .
          2040 2 . . . . .
          2040 3 . . . . .
          2040 4 . . . . .
          2044 1 2 1 1 . .
          2044 2 . . . . .
          2044 3 . . . . .
          2044 4 . . . . .
          2044 5 . . . . .
          2048 1 1 . . . .
          2048 2 . . . . .
          2052 1 . . . . .
          2052 2 2 2 1 . .
          2052 3 . . . . .
          2052 4 . . . . .
          2052 5 . . . . .
          2056 1 . . . . .
          2056 2 2 2 2 . .
          2056 3 . . . . .
          2060 1 . . . . .
          2060 2 1 . . . .
          2060 3 . . . . .
          2064 1 . . . . .
          2064 2 1 . . . .
          2064 3 . . . . .
          2064 4 . . . . .
          2069 1 . . . . .
          2069 2 1 . . . .
          2073 1 1 . . . .
          2073 2 . . . . .
          2073 3 . . . . .
          2073 4 . . . . .
          2073 5 . . . . .
          2077 1 . . . . .
          2077 2 1 . . . .
          2077 3 . . . . .
          2077 4 . . . . .
          2081 1 . . . . .
          2081 2 1 . . . .
          2081 3 . . . . .
          2085 1 1 . . . .
          2089 1 1 . . . .
          2089 2 . . . . .
          2093 1 1 . . . .
          2097 1 1 . . . .
          2105 1 1 . . . .
          2105 2 . . . . .
          2105 3 . . . . .
          2110 1 1 . . . .
          2110 2 . . . . .
          2110 3 . . . . .
          2114 1 . . . . .
          2114 2 1 . . . .
          2114 3 . . . . .
          2118 1 . . . . .
          2118 2 2 4 2 . .
          2118 3 . . . . .
          2118 4 . . . . .
          2122 1 2 1 2 . .
          2126 1 1 . . . .
          3002 1 1 . . . .
          3006 1 1 . . . .
          3006 2 . . . . .
          3006 3 . . . . .
          3006 4 . . . . .
          3010 1 1 . . . .
          3010 2 . . . . .
          3010 3 . . . . .
          3014 1 1 . . . .
          3014 2 . . . . .
          3014 3 . . . . .
          3014 4 . . . . .
          3014 5 . . . . .
          3022 1 1 . . . .
          3022 2 . . . . .
          3022 3 . . . . .
          3022 4 . . . . .
          3022 5 . . . . .
          3026 1 1 . . . .
          end
          label values SH27 SH27_N
          label def SH27_N 1 "No", modify
          label def SH27_N 2 "Si", modify
          label values SH27T_1 SH27T_1N
          label def SH27T_1N 1 "No", modify
          label def SH27T_1N 2 "Si", modify
          label values SH27T_2 SH27T_2N
          label def SH27T_2N 1 "Si", modify
          [/CODE]


          .
          .
          .
          .
          I used this command to create the variable but so far it does not give me the expected result.


          gen SH27T = 1 si SH27 == 2 & (SH27T_1 == 2 | SH27T_2 == 1)
          reemplaza SH27T = 2 si SH27 == 1 | (SH27T_1 == 1 | SH27T_2 == 1)


          Thanks for your time and apologies for the mistakes.

          Comment


          • #20
            I used this command to create the variable but so far it does not give me the expected result.

            gen SH27T=1 if SH27==2 & (SH27T_1==2 | SH27T_2==1)
            replace SH27T=2 if SH27==1 | (SH27T_1==1 | SH27T_2==1)



            Thanks for your time and apologies for the mistakes.

            Comment


            • #21
              I'm sorry, but I don't understand what you are trying to do. The data example you posted is fine, but I don't understand your explanation of what the variables mean and how you are trying to transform them.

              My suggestion is that instead of trying to explain it in general terms, pick out a small number of observations, enough to illustrate the different possibilities, from the data you showed, and then state what the value of SH27T should be for those observations and show how you calculated that.

              Comment


              • #22
                I'm sorry Clyde, my English is not very good, I'll try to explain it again:

                My variables are:
                HHID: Home Identifier
                V003: Identification of members within the home
                SH27: REPORT OF IF ANY MEMBER OF THE HOME SUFFERS FROM X DISEASE?
                (SH27O_ *): TELL ME WHAT CODE DOES THE HOUSEHOLD MEMBER SUFFER FROM X DISEASE?
                (SH27T_ *): Tell me if this family member receives treatment?
                where: * = 1,2,3


                Code:
                * Example generated by -dataex-. To install: ssc install dataex
                clear
                input int HHID byte V003 long SH27 byte SH27O_1 long SH27T_1 byte SH27O_2 long SH27T_2 float(SH27O_3 SH27T_3)
                2003 1 . . . . . . .
                2003 2 1 . . . . . .
                2007 1 1 . . . . . .
                2011 1 2 1 1 3 1 . .
                2011 2 . . . . . . .
                2011 3 . . . . . . .
                2015 1 . . . . . . .
                2015 2 2 2 1 4 0 . .
                2015 3 . . . . . . .
                2015 4 . . . . . . .
                2019 1 . . . . . . .
                2019 2 1 . . . . . .
                2019 3 . . . . . . .
                2023 1 1 . . . . . .
                2028 1 . . . . . . .
                2028 2 2 1 2 2 1 . .
                2032 1 1 . . . . . .
                2036 1 . . . . . . .
                2036 2 1 . . . . . .
                2040 1 1 . . . . . .
                2040 2 . . . . . . .
                2040 3 . . . . . . .
                2044 1 2 1 1 2 1 3 1
                2044 2 . . . . . . .
                2044 3 . . . . . . .
                2048 1 1 . . . . . .
                2048 2 . . . . . . .
                end
                label values SH27 SH27_N
                label def SH27_N 1 "No", modify
                label def SH27_N 2 "Si", modify
                label values SH27T_1 SH27T_1N
                label def SH27T_1N 1 "No", modify
                label def SH27T_1N 2 "Si", modify
                label values SH27T_2 SH27T_2N
                label def SH27T_2N 0 "No", modify
                label def SH27T_2N 1 "Si", modify
                label values SH27T_3 SH27T_3
                label def SH27T_3 1 "Si", modify

                My idea is: to pass these reports that are given horizontally (SH27T_ *) given by a single member AND locate them vertically in their respective identifier (V003) creating a new variable.

                Generate the new variable but when I see the observations created are wrong with respect to horizontally reported:

                gen SH27T=1 if SH27==2 & (SH27T_1==2 | SH27T_2==1)
                replace SH27T=2 if SH27==1 | (SH27T_1==1 | SH27T_2==1)

                Thank you!.

                Comment


                • #23
                  I'm not entirely sure I understand, but perhaps it is this?

                  Code:
                  reshape long SH27O_ SH27T_, i(HHID V003) j(hh_member)
                  rename *_ *

                  Comment


                  • #24
                    Dear Clyde, if that is more or less my idea, I also found this alternative but more observations are created and this database does not only have these variables. My idea is to create a variable that locates its response with a certain member identifier without altering the amount of data already established. Can you actually do it?

                    thanks for the inconvenience taken.

                    Comment


                    • #25
                      Now, I don't understand. I don't at all get how you would create a new variable that shows the different values of SH27T_* without expanding the number of observations. A variable can only have one value per observation. Since there are several SH27T_* that has to becomes several observations.

                      Instead of explaining in words, can you show what you would like the result to look like? Work out a few cases by hand and then post that.

                      Comment


                      • #26
                        Dear Clyde, thank you very much for the support, this is how I would like my data to be shown (yellow column). Could that database be generated, with commands?

                        Click image for larger version

Name:	EXAMPLE.png
Views:	1
Size:	25.7 KB
ID:	1434659

                        Comment


                        • #27
                          Now, I get it.

                          The following works with your example:

                          Code:
                          * Example generated by -dataex-. To install: ssc install dataex
                          clear
                          input int HHID byte V003 long SH27 byte SH27O_1 long SH27T_1 byte SH27O_2 long SH27T_2 float(SH27O_3 SH27T_3)
                          2003 1 . . . . . . .
                          2003 2 1 . . . . . .
                          2007 1 1 . . . . . .
                          2011 1 2 1 1 3 1 . .
                          2011 2 . . . . . . .
                          2011 3 . . . . . . .
                          2015 1 . . . . . . .
                          2015 2 2 2 1 4 0 . .
                          2015 3 . . . . . . .
                          2015 4 . . . . . . .
                          2019 1 . . . . . . .
                          2019 2 1 . . . . . .
                          2019 3 . . . . . . .
                          2023 1 1 . . . . . .
                          2028 1 . . . . . . .
                          2028 2 2 1 2 2 1 . .
                          2032 1 1 . . . . . .
                          2036 1 . . . . . . .
                          2036 2 1 . . . . . .
                          2040 1 1 . . . . . .
                          2040 2 . . . . . . .
                          2040 3 . . . . . . .
                          2044 1 2 1 1 2 1 3 1
                          2044 2 . . . . . . .
                          2044 3 . . . . . . .
                          2048 1 1 . . . . . .
                          2048 2 . . . . . . .
                          end
                          label values SH27 SH27_N
                          label def SH27_N 1 "No", modify
                          label def SH27_N 2 "Si", modify
                          label values SH27T_1 SH27T_1N
                          label def SH27T_1N 1 "No", modify
                          label def SH27T_1N 2 "Si", modify
                          label values SH27T_2 SH27T_2N
                          label def SH27T_2N 0 "No", modify
                          label def SH27T_2N 1 "Si", modify
                          label values SH27T_3 SH27T_3
                          label def SH27T_3 1 "Si", modify
                          
                          tempfile copy
                          save `copy'
                          
                          keep HHID SH27O* SH27T*
                          gen long obs_no = _n
                          reshape long SH27O_ SH27T_, i(obs_no) j(_j)
                          rename *_ *
                          assert missing(SH27O) == missing(SH27T)
                          drop if missing(SH27O)
                          drop obs_no _j
                          rename SH27O V003
                          
                          merge 1:1 HHID V003 using `copy', assert(match using)
                          order SH27T, last
                          sort HHID V003
                          There are some peculiar values in the resulting variable SH27T, but I have verified that in each case they do correspond to values in the input data, so the code is working fine.

                          I think there is a problem with your data, however in that it seems that some of your SH27T_* variables have No/Si as 0/1 and others have them as 1/2. When you put them together in the single variable SH27T the resulting variable makes no sense. So before you do this, you have to recode all of the SH27T_* variables so that they use the same coding for Si and No.

                          Comment


                          • #28
                            This is true ! Thank you Clyde for your patience, I really served that command sent. Very thankful

                            Comment


                            • #29
                              Estimated from one moment to another, when I started using the commands and started to merge I reported an error r (9). How to solve this?

                              Comment


                              • #30
                                Before reposting, please read the Forum FAQ. Perhaps run them through translate.google.com if it would be easier to see them in your native language. Your question is posed with too little information to be answered. The FAQ will explain what information is needed so that others can understand and answer your question.

                                Error r(9) mean an -assert- command encountered an exception to the condition it was verifying. There are two different -assert- commands in the code above, and you do not say which one caused the error message. Also, when encountering problems with code that somebody else has tested on your example, one or both of these must be true:

                                1. You changed the code in some way.
                                2. The real data you are running the code on differs in an important way from the example originally provided.

                                Therefore, whenever you want help troubleshooting code that somebody else has already tested, it is essential to provide:

                                1. The exact code you ran that caused the error, along with the complete output Stata gave you in response to it (not just the error message), and,
                                2. A new data example that reproduces the error you are getting.


                                Comment

                                Working...
                                X