Announcement

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

  • How do I make a value repeat itself across observations per ID?

    I have variables ID, Name, Age and Income. Income is the income of the household head. I want the income for the household head to appear on all the members of the household. How do I do it?

  • #2
    Hi Chonde,
    It depends if you have an appropriate household id . If you do, it can be done as follows:
    Code:
    sort hid h_income
    by hid:replace h_income=h_income[1] if h_income==.
    HTH
    Fernando

    Comment


    • #3
      Thank you Fernando, I have tried your option it is saying weights not allowed.

      Comment


      • #4
        @FernandoRios's code looks good to me, so copy and paste exactly what you tried. My guess is that you are putting [] in the wrong place.

        Comment


        • #5
          Thank you Fendando and Nick. It has worked.

          Comment


          • #6
            I have been try similar to this command but response is still no weights allowed

            Comment


            • #7
              Nobody can help you if you don't show the exact code you tried. And you also need to show example data, using the -dataex- command. If you are running version 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.

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

              Comment

              Working...
              X