Announcement

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

  • Means at a time interval

    Good evening, I'm having a datset with age as the independent variable. Age is given as a point number, i.e. 38.82 for a person who is 38 years and one month old. I'm supposed to get averages three times a year with 1/3 of a year between them. What would be a suitable way of doing so? The examples I've seen in the archives here are unfortunately all for cases where months or days are given as variables.

  • #2
    How does 38.82 represent 38 years and one month? I don't get the logic. 0.82 years is just under 10 months. What is the coding here?

    Averages of what? And what kind of data do you have.

    When asking for help with coding, always show example data. And always use the -dataex- command to do that. If you are running version 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


    • #3
      Hi,

      The 38.82 should say 38.082, as 1 day would be 1/365. The example from the data is:

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input float age int ned float wg_c
       33.82192    .           .
       38.73425   34    .6387262
        39.5726   15  -.26885077
       37.59726 1847    .3594139
       33.47945  687    1.435173
       48.73973  191     .652995
      30.852055   78   -.6590613
       41.23561 1578  -.11746673
      37.736988   41    .6570308
       49.07397  275  -.51291037
       46.49041  347    .9565516
        49.5726 1097   -.4174039
      33.983562   76  -.02404823
      30.260275   87           .
       47.23836  245           .
       48.99178  288   -.5132165
       43.98904  258  -.39206505
       45.90411  214  -.29457772
       34.02192   47  -.05003124
       46.49041  530   .13128398
       39.30411   24   -.1025589
       44.15068  234   .19848554
       41.03014  211   .02514625
      35.564384  216  -1.0500528
      37.983562  134    .3762084
       39.06849  168  -.19183367
       34.70685   72  -.17194057
       48.97534    .           .
       40.89589 1184   -.4963008
       43.81918   77   .19263116
       32.81096  302  -1.1576884
      30.561644   62   .17143446
       39.90137  213  -.04189511
       41.15342  213   -.3270496
       34.68219   27  -.22967665
      31.476713  189    .1932102
       39.49041  609   .28018147
       48.72877   22           .
      33.813698  103           .
      35.750687  512  -.09796067
      37.246574  178   -.1961045
       49.70137   33   .16929014
       48.83014   15 -.008842388
      34.728767 2106   .09558595
      34.767124  127      .31053
       48.28219  144   -.1133074
       30.67671   51    .7986139
       31.89589  275   1.0878267
           33.4  883   -.7202019
       43.54795  101   .10834202
      33.471233 2453  .037116393
      36.232876   73           .
      37.265755   66           .
       38.26301   66           .
       39.26027   67           .
       40.25753   66           .
        41.2548   68           .
       42.25206   66           .
       43.28767   60           .
       44.26575   66           .
       30.19452 4168    1.477306
       44.08493    .           .
       39.40548  719   -.4020715
       31.61918  146    .0449803
      32.769863  111   .08347853
       33.60822   80   .06447457
           34.8   99  .031088047
      36.052055   96           .
      34.942467  230   -.9551919
       45.11507  167  .035923693
       43.40822   60  -.10340602
       38.40274  306  -1.0120952
      37.230137   18    .3292662
      35.564384  111  -.06246318
      30.860273  435   .09615602
       44.31781  215  -.52729386
      34.515068   64           .
       49.77808  250  -.09715204
       46.50959  108    .2386982
       41.23288    .           .
      38.065754   20   .06112232
       42.82466  238   -.3209757
       48.41096    .           .
       33.36986  116           .
      36.854794   54           .
       31.52055  320  .024024496
       44.07123 3811  -.50606906
       30.28493  232    .2231882
       35.10685 2133   .54615825
      37.172604  647  -1.3095566
           48.6    .           .
       49.07671  279   -.9648237
       37.89041  219   .21694164
       42.19178 2029    .1415003
       42.73699   68           .
      32.315067  215  -.04253931
      34.663013    .           .
       32.20548  833   .13294433
       38.36986  210 .0044039316
       30.72877  182   .02291842
      end
      I'm not sure if this is displayed right, the three variables are - from left to right - age (when getting unemployed), ned (for nonemployment duration) and wg_c (for wage change after fnding a new employment). So far, i found out that Stata requires

      (thelibrary is closing, I will finish the post later.

      Comment


      • #4
        (I can't edit the post above, so I'll continue here.)

        So far i found out that Stata requires time series data to be integer values, so any option of using the time series tools doesn't work (and would be questionable given that it's not a time series anyways). I was looking at an solution via egen, but didn't see how i could make cuts every 4 months. Examples i have found have fixed boundaries, i.e. "egen urbcat1 = cut(urb), at(0,34,68,101)". I'm not really sure how to get the cutoff at each 1/3.

        The problem is part of a larger task which basically involves recreating these 4 diagramms. I have the regressor for this given and should know how recreate that, but finding the details is part of this exercise. It's part of a course and we have seen Stata before, but everything about that was theoretical.

        Comment


        • #5
          Code:
          gen  age_group = floor(10*floor(3*age)/3)
          This will give you an integer value variable called age_group. age_group 300 will apply to all ages from 30.0 to 30 + 1/3, agegroup 303 will apply to ages from 30+1/3 to 30+2/3. agegroup 306 will apply to ages from 30+2/3 to 31. 310 gives you 31 to 31+1/3, etc. That is, read the age_group number as if it had a decimal point before the last digit and think of .3 as 1/3, .6 as 2/3.

          Comment


          • #6
            Although Clyde beat me to the posting, here's the approach I took. The variable gage is the age at the center of the interval represented by the group, e.g 30 1/6, 30 3/6, and 30 5/6.
            Code:
            generate group = floor(3*(age-30))+1
            generate gage = 30 + (group-1)/3 + 1/6
            table group, contents(n age min age max age min gage) format(%9.2f)
            Code:
            . table group, contents(n age min age max age min gage) format(%9.2f)
            
            ----------------------------------------------------------
                group |     N(age)    min(age)    max(age)   min(gage)
            ----------+-----------------------------------------------
                    1 |          3       30.19       30.28       30.17
                    2 |          1       30.56       30.56       30.50
                    3 |          4       30.68       30.86       30.83
                    5 |          3       31.48       31.62       31.50
                    6 |          1       31.90       31.90       31.83
                    7 |          2       32.21       32.32       32.17
                    9 |          2       32.77       32.81       32.83
                   11 |          5       33.37       33.61       33.50
                   12 |          3       33.81       33.98       33.83
                   13 |          1       34.02       34.02       34.17
                   14 |          2       34.52       34.66       34.50
                   15 |          6       34.68       34.94       34.83
                   16 |          1       35.11       35.11       35.17
                   17 |          2       35.56       35.56       35.50
                   18 |          1       35.75       35.75       35.83
                   19 |          2       36.05       36.23       36.17
                   21 |          1       36.85       36.85       36.83
                   22 |          4       37.17       37.27       37.17
                   23 |          1       37.60       37.60       37.50
                   24 |          3       37.74       37.98       37.83
                   25 |          2       38.07       38.26       38.17
                   26 |          2       38.37       38.40       38.50
                   27 |          1       38.73       38.73       38.83
                   28 |          3       39.07       39.30       39.17
                   29 |          3       39.41       39.57       39.50
                   30 |          1       39.90       39.90       39.83
                   31 |          1       40.26       40.26       40.17
                   33 |          1       40.90       40.90       40.83
                   34 |          5       41.03       41.25       41.17
                   37 |          2       42.19       42.25       42.17
                   39 |          2       42.74       42.82       42.83
                   40 |          1       43.29       43.29       43.17
                   41 |          2       43.41       43.55       43.50
                   42 |          2       43.82       43.99       43.83
                   43 |          5       44.07       44.32       44.17
                   46 |          1       45.12       45.12       45.17
                   48 |          1       45.90       45.90       45.83
                   50 |          3       46.49       46.51       46.50
                   52 |          1       47.24       47.24       47.17
                   55 |          1       48.28       48.28       48.17
                   56 |          2       48.41       48.60       48.50
                   57 |          5       48.73       48.99       48.83
                   58 |          2       49.07       49.08       49.17
                   59 |          1       49.57       49.57       49.50
                   60 |          2       49.70       49.78       49.83
            ----------------------------------------------------------

            Comment


            • #7
              Stata requires time series data to be integer values
              Not so; only time variables which want to include a tsset or xtset.

              Even if age is a predictor, I can't think that being integer is essential for anything. It seems that you have a bunch of people with different ages. That's not a time series or panel data so far as I can see.

              Comment

              Working...
              X