Announcement

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

  • Modelling variables by single year age from age-groups

    Dear All,

    I am working on IHD data. I have incidence rates and prevalence rates by age-groups (14-19, 20-24, 25-29 years and so on till 95+ years). I want to model these rates by single year of age. Can some please help with the codes. Many thanks in advance.

  • #2
    Lets start with the obvious: If you don't have the age in years, then you don't have the age in years. Stata and statistics can only extract information that is present in the data, they cannot create information out of thin air. So what you want is logically impossible. Statistics is taught at universities, not at Hogwarts.

    You can go to the dataprovider, and see if it is possible to get access to age in years. Groupings like this are often done to protect the privacy of the respondents, so you may have to work on-site or something like that and/or there may be a fee that needs to be paid.

    You can interpolate, which creates pretty graphs, but does not add any information. Here is an example of cubic spline interpolation

    Code:
    // get some example data
    sysuse pop2000, clear
    
    // the value of agelow is the lower bound of the interval
    gen agelow = (agegrp-1)*5
    // convenient way of adding value labels, not neccesary but nice
    // type -findit labmask- to find and install it
    labmask agelow, values(agestr)
    
    // total in milions
    // I use 1e6 instead of 1000000 because I always miscount 0s
    // With 1e6 I just know a 1 with six 0s, and I don't have to count
    gen tot_mil = total/1e6
    
    mata:
    // get the data in Mata
    x = st_data(.,"agelow")
    y = st_data(.,"tot_mil")
    
    // compute the interpolation
    splineinfo = spline3(x,y)
    xprime = (0.. 80)'
    yint = spline3eval(splineinfo,xprime)
    
    // get the interpolation in Stata
    newobs = rows(xprime) - st_nobs()
    st_addobs(newobs)
    st_addvar("byte","x")
    st_addvar("float", "y")
    st_store(.,"x",xprime)
    st_store(.,"y",yint)
    end
    
    // view the result
    twoway line y x || scatter tot_mil agelow
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	68.6 KB
ID:	1777222

    Last edited by Maarten Buis; 12 May 2025, 02:53.
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Many thanks, Maarten. Much appreciated.

      Comment

      Working...
      X