Announcement

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

  • Sequence Analysis - sqindexplot: change y-axis from n to proportion?

    Dear Statalisters

    I am using the *Sequence analysis with Stata' package to visualize body weight changes over time using
    Code:
    sqindexplot
    For now, I can only shown 'n' on the y-axis, but I would like to have proportions instead.
    Anyone who know how to do this? I have attached the plot and my code.
    I have tried
    Code:
    sqpercentageplot
    but it does not show how people changes weight status.

    Kind regards,
    Jannie

    Code:
    sqindexplot if Asample==1, color(green yellow orange red black) graphregion( color(white) ) legend (rows(5) size(vsmall)) ///
    xtitle("Years of follow-up") xlabel(0 "0" 1 "2" 2 "4" 3 "6" 4 "8" 5 "10" 6 "12" 7 "14" 8 "16" 9 "18" 10 "20" 11 "22") ///
    ytitle("n", height(10))
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	80.2 KB
ID:	1762348
    Last edited by JN Nielsen; 26 Aug 2024, 03:18.

  • #2
    Ulrich Kohler may be able to help.

    Code:
    search mylabels, sj
    which may be part of a solution.

    Otherwise, note the typo "Overweigth" -- which should be "Overweight".

    Comment


    • #3
      There is nothing build-in in sqindexplot, but a variant of the following might be good enough as a workaround:

      Code:
      . sqset
      . local n = r(imax)
      . sqindexplot , ylab(5000 "`=5000/`n'" 1000 "`=10000/`n'")

      Comment


      • #4
        #3 is identical in spriit to what mylabels offers. Let's suppose that the number of people behind #1 is 13500.

        mylabels creates a local macro you can use in your graph command.

        Code:
        . mylabels 0 0.25 0.5 0.75 1, myscale(@*13500) local(yla)
        0 "0" 3375 ".25" 6750 ".5" 10125 ".75" 13500 "1"
        In practice l like to see something like 0 0.25 0.5 0.75 1 and would edit in extra leading zeros as explicit characters.

        Comment


        • #5
          Many thanks for your replies Ulrich Kohler and Nick Cox
          Honestly, Im (still) not great with macros. I could not make Ulrich's code work.
          With Nick's I read your article 'Speaking Stata...' and tried following:
          Code:
          scc install mylabels
          mylabels 0.0 0.25 0.5 0.75 1, myscale(@*13401) local(yla)
          0 "0" 3350 ".25" 6700 ".5" 10051 ".75" 13401 "1"
          sqindexplot if Asample==1, color(green yellow orange red black) graphregion( color(white) ) legend (rows(5) size(vsmall)) ///
          xtitle("Years of follow-up") xlabel(0 "0" 1 "2" 2 "4" 3 "6" 4 "8" 5 "10" 6 "12" 7 "14" 8 "16" 9 "18" 10 "20" 11 "22") ///
          ytitle("Proportion", height(10)) ylabel(‘yla’)
          and
          Code:
          sqindexplot if Asample==1, color(green yellow orange red black) graphregion( color(white) ) legend (rows(5) size(vsmall)) ///
          xtitle("Years of follow-up") xlabel(0 "0" 1 "2" 2 "4" 3 "6" 4 "8" 5 "10" 6 "12" 7 "14" 8 "16" 9 "18" 10 "20" 11 "22") ///
          ytitle("Proportion") ylabel(‘yla’) yscale((@))
          However, for both I get the error 'invalid label specifier, : ‘yla’:'

          Two last questions:
          - can sq work with survey weighted data? (svy command)
          - can sq calculate 'entropy'?

          Kind regards,
          Jannie

          Comment


          • #6
            First off, as implied by #2 mylabels should be referenced as coming from the Stata Journal and should in principle be installed from there. In practice, using ssc to install should be fine in this instance.

            But there is no command scc to do that -- that should be ssc.

            There may be other typos in what you post but it looks as if you're using the wrong quotation marks,

            Code:
            ylabel(`yla')
            Confusingly, no doubt, the correct right quotation marks display as a vertical mark in many fonts.

            I would be surprised if yscale((@)) worked. to do anything.

            The other questions are for Ulrich Kohler


            Comment


            • #7
              Nick Cox commented on your questions regarding the error message you got from Stata. I have nothing to add to Nick's answer. But here are the answers to the two other questions:

              (1) Can sq work with survey weighted data? (svy command)

              No. The SQ-Ados are merely a technique to classify the sequences observed in the data at hand. Consider the SQ-Ados just as a kind of -generate-/-replace- command for the construction of a very specific data management task. The concept of sampling weights, standard error or significance tests are thus meaningless.

              Having said that you can, of course, apply -svy- concepts when you analyse the results of the SQ-Ados. For example, if you created clusters of sequences with -sqom- and subsequent cluster analysis, you calculate the standard error of the proportions of the clusters the usual way, and you can also do significance tests on differences in proportions and means. Perhaps this is what you have in mind.


              (2) can sq calculate 'entropy'?

              No, (but yes, perhaps). I haven't implemented any of the entropy-measures proposed for sequences. However, -sqom- has the option -sadi()-, which is a call to Brendan Halpins C-plugin for sequence analysis that takes advantage of the settings of the SQ-Ados. If this plugin offers some entropy measures it may run with -sqom, sadi(XXX)-. I haven't checked the functionality of sadi for years, and admittedly I don't even know if -sqom-'s interface to -sadi- still works. But it may be worth a try.


              Comment


              • #8
                Once again - many thanks for your inputs! Makes sense with the survey weights. I will check out the sqom sadi option.

                Nick Cox - my untrained (or just old) eyes did not catch the difference between the type of quotation marks - thanks for correcting.

                But code is still not changing the y-axis. Issue may be the mylabels command. If I mark both lines before running the code, I getfollowing:
                Code:
                mylabels 0(0.25)1, myscale(@*13401) local(yla)
                0 "0" 3350.25 ".25" 6700.5 ".5" 10050.75 ".75" 13401 "1"
                
                0 "0" 3350 ".25" 6700 ".5" 10051 ".75" 13401 "1"
                
                0 is not a valid command name
                r(199);
                However, if I only mark the first line (starting with 'mylabels'), code runs, but but y-scale does not change (see figure)

                Code:
                adoupdate mylabels
                
                mylabels 0(0.25)1, myscale(@*13401) local(yla)
                0 "0" 3350 ".25" 6700 ".5" 10051 ".75" 13401 "1"
                
                sqindexplot if Asample==1, color(eltgreen green ebblue edkblue black) graphregion( color(white) ) legend (rows(5) size(vsmall)) ///
                xtitle("Years of follow-up") xlabel(0 "0" 1 "2" 2 "4" 3 "6" 4 "8" 5 "10" 6 "12" 7 "14" 8 "16" 9 "18" 10 "20" 11 "22") ///
                ytitle("Proportion") ylabel(`yla')
                Kind regards,
                Jannie
                Click image for larger version

Name:	Graph1.png
Views:	1
Size:	83.8 KB
ID:	1763360

                Comment


                • #9
                  Copying the mylabels output to the command line won't work -- it's not a command.

                  Referring to the local macro yla within a sqindexplot command should work.

                  Make sure that the command can see the local macro.

                  https://journals.sagepub.com/doi/pdf...36867X20931028

                  Comment


                  • #10
                    Thanks! its working!

                    Comment

                    Working...
                    X