Announcement

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

  • Creating a spikeplot with labeling specific values

    Hi,
    I would like to get a spikeplot just like in the figure attached.
    I need some of the spikes labelled with the value on the x axis (like 26, 36, 42,...)
    I would also be greatful for the entire code to create a spikeplot like that. I could only do it with the graph editor.
    Thanks for any help.
    Attached Files

  • #2
    You want the entire code but you're not giving us the data! This may help.

    Code:
    webuse ghanaage
    spikeplot age [fw=pop], ytitle("Population in 1000s") xlab(0(10)90) xmtick(5(10)85)
    
    spikeplot age [fw=pop], ytitle("Population in 1000s") xlab(0(10)90) xmtick(5(10)85) legend(off) /// 
    addplot(scatter pop age if inlist(age, 26, 36, 42, 56, 66), ms(none) mla(age) mlabc(black) mlabpos(12) mlabsize(vsmall))

    Comment


    • #3
      I am sorry, I forgot the data.
      Here it is.
      The code didn't work because I have only one column of data.
      Thank you!
      Attached Files

      Comment


      • #4
        I won't even try to open a spreadsheet file. We do explain why. On that, and "didn't work", please do read and act on https://www.statalist.org/forums/help#stata

        Comment


        • #5
          I am sorry, here it is:
          Code:
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input byte age_all
          32
          60
          28
          51
          40
          25
          32
          17
          19
          24
          28
          31
          35
          33
          28
          40
          36
          25
          41
          19
          21
          33
          21
          33
          67
          35
          20
          27
          27
          30
          24
          34
          24
          34
          43
          50
          56
          29
          23
          24
          31
          43
          24
          31
          25
          20
          45
          24
          23
          58
          36
          42
          39
          45
          16
          15
          11
          41
          42
          36
          49
          53
          28
          43
          21
          36
          27
          27
          22
          34
          20
          34
          20
          36
          42
          33
          45
          39
          36
          35
          25
          49
          32
          60
          54
          21
          24
          23
          24
          30
          38
          37
          29
          20
          31
          21
          35
          18
          40
          40
          end
          These are the ages for which I need a spikeplot.
          Thanks for your patience and time.

          Comment


          • #6
            One twist and the same approach is possible:


            Code:
            contract age_all
            spikeplot age_all [fw=_freq]
            Evidently _freq here corresponds to pop.

            Comment


            • #7
              Thank you very much! Finally, it works. I appreciate that.

              Comment


              • #8
                Some different technique:

                Code:
                set scheme s1color 
                ssc install stripplot 
                
                stripplot age, stack ms(Sh) aspect(0.14) ///
                xaxis(1 2) xla(10(10)70, axis(2)) xtick(15(10)65, axis(2)) xtitle("age", axis(2))  ///
                xtitle("", axis(1)) xla(26 36 42 56 66, grid glc(gs8) glw(thin) axis(1))

                Click image for larger version

Name:	ages.png
Views:	1
Size:	18.5 KB
ID:	1456909

                Comment


                • #9
                  Thanks! I will try this out.

                  Comment


                  • #10
                    Now, I have got this graph. My topic is age heaping btw and I would like to show a curve on this graph which shows a distribution as if there was no heaping. Can you help me?
                    Attached Files

                    Comment


                    • #11
                      There seems a mix here of fairly generic patterns (preferences for 0 and 5 as final digits) and some culture-specific details.

                      I would smooth the frequencies with a binomial filter with weights 1 4 6 4 1. If you want us to play you have to give us the frequencies, a dataset with 60 or so observations.

                      Comment


                      • #12
                        Here it is. Thanks.

                        Code:
                        * Example generated by -dataex-. To install: ssc install dataex
                        clear
                        input byte age int freq
                        11   1
                        12   0
                        13   2
                        14   3
                        15   7
                        16  11
                        17  22
                        18  59
                        19  78
                        20 123
                        21 107
                        22 118
                        23 137
                        24 141
                        25 122
                        26 102
                        27 109
                        28 111
                        29  89
                        30 143
                        31  76
                        32  89
                        33  81
                        34  75
                        35  89
                        36  70
                        37  69
                        38  55
                        39  38
                        40  95
                        41  24
                        42  37
                        43  26
                        44  21
                        45  58
                        46  27
                        47  28
                        48  30
                        49  23
                        50  33
                        51  11
                        52  11
                        53   9
                        54  13
                        55  13
                        56  13
                        57   7
                        58   8
                        59   5
                        60  11
                        61   2
                        62   2
                        63   3
                        64   7
                        65   5
                        66   3
                        67   3
                        68   4
                        69   2
                        70   3
                        71   0
                        72   1
                        73   1
                        74   0
                        75   0
                        end

                        Comment


                        • #13
                          This is indicative, naturally, not definitive. 5 term binomial is just the convolution of 3 term binomial repeated. I add twicing.

                          The result looks a little undersmoothed, but flags the biggest anomalies at 30, 40, 45 in a fairly simple way.

                          Code:
                          * Example generated by -dataex-. To install: ssc install dataex
                          clear
                          input byte age int freq
                          11   1
                          12   0
                          13   2
                          14   3
                          15   7
                          16  11
                          17  22
                          18  59
                          19  78
                          20 123
                          21 107
                          22 118
                          23 137
                          24 141
                          25 122
                          26 102
                          27 109
                          28 111
                          29  89
                          30 143
                          31  76
                          32  89
                          33  81
                          34  75
                          35  89
                          36  70
                          37  69
                          38  55
                          39  38
                          40  95
                          41  24
                          42  37
                          43  26
                          44  21
                          45  58
                          46  27
                          47  28
                          48  30
                          49  23
                          50  33
                          51  11
                          52  11
                          53   9
                          54  13
                          55  13
                          56  13
                          57   7
                          58   8
                          59   5
                          60  11
                          61   2
                          62   2
                          63   3
                          64   7
                          65   5
                          66   3
                          67   3
                          68   4
                          69   2
                          70   3
                          71   0
                          72   1
                          73   1
                          74   0
                          75   0
                          end
                          
                          tsset age 
                          tssmooth nl sm_freq=freq, sm(HH, twice) 
                          su *freq
                          line sm_freq age, lc(gs8)  || rspike freq sm_freq age, lc(blue) legend(off) ///
                          ytitle(Frequency) xtitle(Age) note(5 term binomial with twicing) xla(10(10)70)
                          Click image for larger version

Name:	ageheap.png
Views:	1
Size:	26.7 KB
ID:	1457024

                          Comment


                          • #14
                            Sorry, I haven't been online for a week, but thank you very much!

                            Comment

                            Working...
                            X