Announcement

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

  • HELP! xtline producing different graphs each run

    Please help!

    I have a simple, balanced longitudinal data set. I xtset the data and then run xtline. Each time I run xtline I am getting a completely different graph that does not reflect the summary data.

    Any ideas why this is happening and how I can fix it??

    Below is my code:

    egen id = group(study_id)
    sort id visit_month
    drop study_id
    xtset id visit_month

    bysort arm visit_month: sum hfais_summary
    xtline hfais_summary, recast(connected) i(id) t(visit_month)

    bysort arm visit_month: sum wealthscore
    xtline wealthscore, recast(connected) i(arm) t(visit_month)

    bysort arm visit_month: sum social_support_sum
    xtline social_support_sum, recast(connected) i(arm) t(visit_month)

  • #2
    There is no reason I can see why the graph produced for hfais_summary would not reproduce properly. But I would expect nothing but trouble in the wealthscore and social_support_sum graphs. What is this variable arm? Unless arm and visit_month together uniquely identify observations in the data set, the sort order resulting from -bysort arm visit_month- will be indeterminate, and irreproducible from one run to the next. -xtline- then takes the data in whatever sort order it finds them, which results in weird graphs where there are multiple points for every visit_month and they are connected in different orders each time. Nor is there any clear solution to this problem because -xtline- is simply not designed to handle situations like that. You would have to clarify what you actually want in these graphs and then perhaps code could be found that would produce it.

    The simplest way to be sure whether arm and visit_month uniquely identify observations is to run
    Code:
    isid arm visit_month
    If arm and visit do uniquely identify observations in the data, there will be no output from this command. If they don't, you will see an error message telling you that.

    If arm and visit_month do uniquely identify observations in the data, then their should be no problem at all. In that case, please post back with example data that exhibits the problem you are encountering, using the -dataex- command to do that, and it will be possible to troubleshoot further. In the future, when showing data examples, please use the -dataex- command to do so. If you are running version 17, 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
      Thank you for your speedy response.

      arm = the trial arm (1=intervention, 2=control)
      id = patient id (there are two observations for each patient, 1 at visit_month=0 and 1 at visit_month=9)

      I want to graph the change in summary scores from month 0 to month 9, sectioned by trial arm. The following graph is the format that I want (i.e., I am not getting any error from Stata when I run the code and so cannot run dataex since I am not getting an error), the graph output is completely different each time I run the xtline command.

      Attached Files

      Comment


      • #4
        attached example
        Attached Files

        Comment


        • #5
          I am not getting any error from Stata when I run the code and so cannot run dataex since I am not getting an error)
          This makes no sense. You can run -dataex- on any Stata data set. It has nothing to do with whether you are getting error messages or not.

          However, from your description additional, it is clear to me that the source of the problem is precisely what I said in #2. The variables arm and visit_month clearly do not jointly identify unique observations in the data set because each combination of arm and visit_month will corresponds to numerous observations: one for each id in the arm that have data from that visit month. The kind of graph you say you want:
          I want to graph the change in summary scores from month 0 to month 9, sectioned by trial arm. [emphasis added]
          cannot be drawn directly from a data set of individual observations. You need to first reduce the data set itself into summary data:

          Code:
          collapse (mean) hfais wealthscore social_support_sum, by(arm visit_month)
          xtset arm visit_month
          xtline hfais, recast(connected)
          graph save hfais, replace
          xtline wealthscore, recast(connected)
          graph save wealthscore, replace
          xtline social_support_sum, recast(connected)
          graph save social_support_sum, replace

          Comment


          • #6
            Clyde, Thanks very much for this helpful comment. This largely gives me what I want - I will play around with it some more. Thanks again!

            Comment

            Working...
            X