Announcement

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

  • Panel data: Survey egen rowfirst function

    Hello,

    I'am a master student Finance from the university of Groningen (the Netherlands). For my thesis I use an unbalanced panel dataset of more than 24,000 observations over 14 years. I investigate the influence of parental financing teaching on financial behavior of children in their adulthood. My database consist of an annual survey who is filled in by many households. Each year the same households are interviewed, therefore some questions are answered only in one year (for example, the answer on the question "received you Pocket Money when you was between 8 -12 years). This is a problem when I use a panel data because in the rest of the years I have no value for this variable. So my question is, is there a function in Stata what I can use for the missing years. In other words when a respondent have filled in, in 2002 for example, that he received Pocket Money, this question was not answered in 2003 however the answer is still yes. So how can i get the answer yes for this variable for the years after and before 2002? I have tried the egen rowfirst function, but it does not work.

    I hope one of you can help me!

    Thank you,

    Annewil Homan

  • #2
    Annewil:
    welcome to the list.
    Maybe what follows can give you some guidance:
    Code:
    . set obs 5
    . g id=1
    . g year=_n
    . expand 2
    . replace id=2 in 6/10
    . g Question="yes" in 1
    . replace Question="no" in 6
    . bysort id: replace Question=Question[1]
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      This sounds like an interpolation problem, but watch out. Interpolation should, arguably, only be used before data analysis when you know what the missing values "should be". Otherwise you take responsibility for changing the data.

      http://www.statalist.org/forums/foru...-interpolation

      Comment


      • #4
        Thanks for the quick responses. But i am not sure if your solutions are the best for my problem.
        I guess I have not explained it very well, my excuses for that.
        In the picture, in the attachment, you can see my data. I try to get the value ,for example, respondent 601 year 2004(row9; value 4), also for the same respondent (601) in the years before 2004 (it is now a missing value). Because it is an quesiton about his childhood so the answer do not change over years. However, I have not found the best function in Stata to get this. I hope you can help me!

        Thanks a lot!

        Annewil Homan

        Comment


        • #5
          Sorry, but your attachment is not readable (by me). FAQ Advice is explicit (http://www.statalist.org/forums/help#stata)

          Screenshots are possible but often do not help much. Even if they are legible, and they often are not, they do not allow copy and paste.
          I suggest that you use dataex (SSC) to give us an example we can read, copy and paste.

          Comment


          • #6
            Thank you for your response. Sorry I do not know that.
            I have tried to get it in another format but Stata is new for me, so I do it now on the following manner (and I have add a word document in the attachment, hopefully you can open that document?)
            I have now for example this dataset

            IDrespondent Year Pocketmoney
            1 2000 4
            1 2001 .
            1 2002 .
            1 2003 .

            How i get for the years where the variable Pocketmoney is missing , in this example, the value 4?

            Thanks,

            Annewil Homan
            Attached Files

            Comment


            • #7
              I guess the user-written "carryforward" (David Kantor) would probably apply to your query. Please check it out by typing - findit carryforward - in the command window.
              Best regards,

              Marcos

              Comment


              • #8
                Annewil: You are new here which is precisely why you should read the FAQ Advice

                http://www.statalist.org/forums/help

                and act upon it. Please see its advice about MS Word documents. Many people here don't even use MS Word. The only software you should assume to be accessible to all here is Stata.

                mipolate is pitched more generally than carryforward (SSC). For the example you give, its forward option is precisely what you ask for, which is why I mentioned it in the first plae.

                Comment


                • #9
                  Thank you for the responses.
                  I think I have found the solution with the bysort ID: egen Pockemoneynew = mode (Pocketmoney)

                  Thanks a lot!

                  Comment


                  • #10
                    That's riskier. You may end up imputing the mode when there are two or more distinct known values in a panel.

                    If that's precisely what you want and can justify, then OK, but using mipolate, groupwise with by: is a safer way to work.

                    Comment


                    • #11
                      Thank you for your advice

                      Comment

                      Working...
                      X