Announcement

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

  • Recursion in Stata

    Hi all,
    I'm currently trying a project using regression in stata to predict children's heights, using their parents. I'm trying to find predicted heights after 1,2,3,.... N generations and my first thought was to use a recursive expression that takes the previous predicted height and inputs that back into the regression formula until the difference between generations is below a threshold (say 0.1) and we can determine a convergence to a height. I was hoping to program this within a loop to modify starting heights also. Is there any guidance on anything similar I can access.
    Thanks.

  • #2
    I'm not quite sure what you want, nor think this might be a good idea to perform. Predicting children's heights from that of their parents is a fairly famous example of regression to mean, demonstrated by Francis Galton in the 19th century.

    Comment


    • #3
      Hi Leonardo,
      Thanks for your response.
      Regression to the mean is exactly what I'm investigating. I have a modern data set of heights and I'm using a regression to see if heights will converge to a mean in the future. The query I have is about determing if its possible to code this in stata so I do not have to repeatedly type it. That is, stata takes the output of y = ax + b then inputs that in again. For example, the height of the second generation given as y = a(ax+b) +b and so on until it converges. I hope this might provide some more clarity to my question.
      thanks

      Comment


      • #4
        I'm not sure I'd call this recursion, but here's a simple code that might illustrate something like what you want:
        Code:
        clear
        local nrep = 10 //  generations
        local N  = 100000 // pop. size
        set obs `N'
        //
        gen height0 = rnormal(69,3)  // approx U.S. mean/sd for males
        summ height0
        local mean = r(mean)
        local sd = r(sd)
        //
        forval i = 1/`nrep' {
           local previous = `i' -1
           // Some regression function connecting each observation's
           // height to that of the parent in the previous generation.
           // Put in here the function you want.
           gen height`i' =  height`previous' + rnormal(0, 0.7* `sd')
        }
        //
        // Summarize relationships of parent/child heights over time. You might
        // want something different.
        corr height

        Comment


        • #5
          Hi Mike,
          This is very helpful thank you, I am experiencing some confusion about what you mean by the regression function, height to that of the parent in previous generation, and the function I want to input. In my data the regression function is roughly ChildH = 25+ 0.7*ParentH but I am not quite sure of the other function to input. Moreover, I was wondering if it would be possible to place this within another loop to be used for different starting heights, for example I want generation 1 heights to be 60, 62, 64, 66, 68 etc to show it converges for all values.
          Thanks

          Comment


          • #6
            I don't understand what you want here. By "regression function," I mean the expression by which you want to link parent's height to child's height, which apparently is ChildH = 25+ 0.7*ParentH. I don't know what you mean by "other function." My sense here is that what you want is not hard to program, but I don't know what that is. Perhaps you can get some colleague to help you describe differently what you want, and perhaps someone else here will understand your intention.

            Yes, you could have different starting height distributions.

            Comment


            • #7
              Hi Mike,
              I've figured out my problem using your code and familiarising myself with Stata a bit more.
              Thank you for all your help.
              All the best

              Comment

              Working...
              X