Announcement

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

  • Combine histogram and connected line graph over time

    Dear Statalist forum users, I came across this graph in a published paper and want to produce a similar graph. The red dots are the mean of the variable, and the blue bars are the distribution of the variable in each year. They used a Stata command "cefhist", which I cannot find anywhere. I assume the authors wrote the program themselves. I have many years of data and don't necessarily want to show histograms for every year. I also attached the data sample. Thank you!
    Click image for larger version

Name:	Screen Shot 2021-10-24 at 15.41.11.png
Views:	1
Size:	37.7 KB
ID:	1633089

    Code:
    input year    data    id
    2000    243.4    1001
    2001    168.5    1001
    2002    119.5    1001
    2003    155.2    1001
    2000    98.3    1003
    2001    84.8    1003
    2002    81    1003
    2003    80.4    1003
    2000    272    1005
    2001    225.9    1005
    2002    307.3    1005
    2003    152.5    1005
    2000    145.9    1007
    2001    124.6    1007
    2002    143.5    1007
    2003    166.9    1007
    2000    3.9    1009
    2001    7.7    1009
    2002    13.3    1009
    2003    11.2    1009
    2000    483.4    1011
    2001    414    1011
    2002    391.4    1011
    2003    292.4    1011
    2000    437.1    1013
    2001    442.9    1013
    2002    510.5    1013
    2003    385.2    1013
    2000    300    1015
    2001    254.8    1015
    2002    292.2    1015
    2003    214.2    1015
    2000    322.8    1017
    2001    234.5    1017
    2002    197.7    1017
    2003    154.4    1017
    2000    91.8    1019
    2001    83.4    1019
    2002    33.3    1019
    2003    24.9    1019
    2000    90.2    1021
    2001    94.7    1021
    2002    46.8    1021
    2003    48.9    1021
    2000    113.4    1023
    2001    114.8    1023
    2002    149.6    1023
    2003    111.8    1023
    2000    259    1025
    2001    279    1025
    2002    242.2    1025
    2003    232.8    1025
    2000    56.2    1027
    2001    98.4    1027
    2002    169.7    1027
    2003    78.3    1027
    2000    91.9    1029
    2001    77.6    1029
    2002    55.7    1029
    2003    13.9    1029
    2000    179.2    1031
    2001    192.8    1031
    2002    203.8    1031
    2003    136.5    1031
    2000    169.1    1033
    2001    138.6    1033
    2002    142.9    1033
    2003    209.8    1033
    2000    71.4    1035
    2001    144.2    1035
    2002    263.3    1035
    2003    149    1035
    2000    228.9    1037
    2001    196.6    1037
    2002    113.1    1037
    2003    122.9    1037
    2000    146.7    1039
    2001    146.2    1039
    2002    76.4    1039
    2003    76.7    1039
    2000    117    1041
    2001    190.1    1041
    2002    81.2    1041
    2003    96    1041
    2000    29.7    1043
    2001    16.8    1043
    2002    25.7    1043
    2003    44.8    1043
    2000    136.6    1045
    2001    155.2    1045
    2002    192.4    1045
    2003    101    1045
    2000    561.4    1047
    2001    479.7    1047
    2002    521.1    1047
    2003    447.2    1047
    2000    21.7    1049
    2001    12.2    1049
    2002    32    1049
    2003    24.2    1049
    2000    129.9    1051
    2001    111.1    1051
    2002    103.3    1051
    2003    81.4    1051
    2000    135.3    1053
    2001    163.7    1053
    2002    140.8    1053
    2003    115.6    1053
    2000    147.1    1055
    2001    137    1055
    2002    130.3    1055
    2003    103.2    1055
    2000    70.2    1057
    2001    86.9    1057
    2002    54.6    1057
    2003    164.7    1057
    2000    38.4    1059
    2001    67.4    1059
    2002    58.4    1059
    2003    91.1    1059
    2000    70    1061
    2001    74.6    1061
    2002    90.6    1061
    2003    43.3    1061
    2000    384.1    1063
    2001    407.7    1063
    2002    429    1063
    2003    217.5    1063
    2000    371.9    1065
    2001    284.6    1065
    2002    343.6    1065
    2003    227.5    1065
    2000    135    1067
    2001    166.1    1067
    2002    128.9    1067
    2003    91.8    1067
    2000    215.9    1069
    2001    238.1    1069
    2002    208.1    1069
    2003    142.5    1069
    2000    44.5    1071
    2001    29.7    1071
    2002    52.2    1071
    2003    41.1    1071
    2000    455.7    1073
    2001    393    1073
    2002    377.2    1073
    2003    298.2    1073
    2000    56.6    1075
    2001    102.8    1075
    2002    65.3    1075
    2003    86.3    1075
    2000    103.5    1077
    2001    112.2    1077
    2002    104.8    1077
    2003    142.6    1077
    2000    126.2    1079
    2001    94.7    1079
    2002    83.7    1079
    2003    90    1079
    2000    213.1    1081
    2001    156    1081
    2002    136.3    1081
    2003    179.7    1081
    2000    106.2    1083
    2001    93.1    1083
    2002    105.8    1083
    2003    91.6    1083
    2000    541.9    1085
    2001    543.4    1085
    2002    438.9    1085
    2003    398.3    1085
    2000    470    1087
    2001    359.2    1087
    2002    343.2    1087
    2003    276.3    1087
    2000    177    1089
    2001    218.3    1089
    2002    215.5    1089
    2003    229.6    1089
    2000    164.3    1091
    2001    176.2    1091
    2002    167.2    1091
    2003    168.9    1091
    2000    45    1093
    2001    39.3    1093
    2002    39.8    1093
    2003    33.4    1093
    2000    59.5    1095
    2001    37.7    1095
    2002    33.7    1095
    2003    21.5    1095
    2000    385.3    1097
    2001    416.7    1097
    2002    322.6    1097
    2003    277    1097
    2000    288.1    1099
    2001    287.4    1099
    2002    231    1099
    2003    144.4    1099
    2000    744.6    1101
    2001    659.3    1101
    2002    579.7    1101
    2003    642.3    1101
    2000    158.3    1103
    2001    182    1103
    2002    218.1    1103
    2003    238.5    1103
    2000    237.1    1105
    2001    197.8    1105
    2002    130.3    1105
    2003    160    1105
    2000    230.1    1107
    2001    231    1107
    2002    140.4    1107
    2003    187.4    1107
    2000    515    1109
    2001    320.8    1109
    2002    225.4    1109
    2003    278.8    1109
    2000    160.9    1111
    2001    107    1111
    2002    125    1111
    2003    116.9    1111
    2000    373.6    1113
    2001    234.3    1113
    2002    255.8    1113
    2003    283.2    1113
    2000    49.8    1117
    2001    32.1    1117
    2002    38.3    1117
    2003    37.5    1117
    2000    33.8    1115
    2001    48.5    1115
    2002    29.8    1115
    2003    33.7    1115
    2000    550    1119
    2001    378.6    1119
    2002    439    1119
    2003    371.9    1119
    2000    287.3    1121
    2001    223    1121
    2002    233.1    1121
    2003    214.3    1121
    2000    225.7    1123
    2001    232.5    1123
    2002    205.6    1123
    2003    162.5    1123
    2000    473.8    1125
    2001    495.1    1125
    2002    296.2    1125
    2003    306.6    1125
    2000    82.1    1127
    2001    90.7    1127
    2002    98.5    1127
    2003    141    1127
    2000    254.5    1129
    2001    173.6    1129
    2002    101.3    1129
    2003    101.6    1129
    2000    525.1    1131
    2001    202    1131
    2002    217.1    1131
    2003    336.8    1131
    2000    16.1    1133
    2001    12.3    1133
    2002    28.7    1133
    2003    20.6    1133
    end

  • #2
    I can confirm that -search cefhist- does not return any results. And Google searches on <Stata cefhist> are fruitless too. Have you tried contacting the corresponding author?
    --
    Bruce Weaver
    Email: [email protected]
    Web: http://sites.google.com/a/lakeheadu.ca/bweaver/
    Version: Stata/MP 18.0 (Windows)

    Comment


    • #3
      The y axis here seems to go from -0.05 to 1.05. What’s that all about?

      Comment


      • #4
        WIth your example dataset some fooling around might be of interest. stripplot is from SSC and tabplot is from the Stata Journal.

        Code:
        set scheme s1color 
        
        stripplot data, over(year) vertical cumul refline center xla(, tlc(none)) xtitle("") name(G1, replace)
        
        gen bin = 25 + 50 * floor(data/50)
        egen mean = mean(data)  , by(year)
        tabplot bin year, barw(50) horizontal yasis yla(0(100)800) ytitle(data) bfcolor(none) addplot(connected mean year, sort) xasis xtitle("") note("") name(G2, replace)
        Click image for larger version

Name:	yichao_G1.png
Views:	1
Size:	42.3 KB
ID:	1633225


        Click image for larger version

Name:	yichao_G2.png
Views:	1
Size:	25.0 KB
ID:	1633226

        Comment


        • #5
          Thank you Nick Cox. That's very helpful!

          Comment

          Working...
          X