Announcement

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

  • To make Trajectory Plot directly using WIDE data format without reshaping to long format

    Dear all,

    Is there any easy command or way to make a trajectory plot using WIDE format without reshaping it to long format?

    So far I found the user-written command profileplot which is easy and convenient by simply inputting:
    profileplot time1 time2 time3 time4, by(id)

    However, profileplot has limited graph options; for example, unable to adjust axis scale and axis label font.

    The rest choices like xtline, graph twoway line, traj package, etc. requires long format data.
    I tried to avoid reshaping data, each reshaping increases the risk to cause error.
    profileplot command is really a smart creation. Why STATA did not continue to develop more comprehensive graph options on profileplot command?

    Thank you and looking forwards to any solution.


  • #2
    profileplot is a community-contributed command from https://stats.idre.ucla.edu/stat/stata/ado/analysis as you are asked to explain (FAQ Advice #12).

    Your question (edited slightly, mainly to use the correct program name: FAQ Advice #18)

    Why did Stata not continue to develop more comprehensive graph options for the profileplot command?
    is hard to answer. Phil Ender, the author of the command, is retired. StataCorp, the company, certainly don't undertake to maintain community-contributed commands. As profileplot allows options of xtline, your claim about options not being allowed appears incorrect to me. You don't give any examples of code you tried that didn't work.

    More crucially, profileplot really isn't the exception you think. It's in essence a wrapper command for reshape long and xtline.

    Bad news for you is that wide layout really is a dead end here. There is no need to presume that there is a risk of error in reshape long

    In your case

    Code:
    reshape long time, i(id) j(whatever) 
    rename (whatever time) (time whatever)
    is what you need. Naturally it would be a good idea to choose a better name than whatever and indeed an informative variable label.

    If you gave a data example (FAQ Advice #12 again) and more details of what you want in your graph, then further help should be possible.

    Comment


    • #3
      I tried to avoid reshaping data, each reshaping increases the risk to cause error.
      I installed the profileplot command from SSC and looked at profileplot.ado.

      This very simple ado starts with a preserve command, the does a keep to retain just the variables needed for plotting, then - not surprisingly - does a reshape long to get the data into shape to collapse and then plot using xtline. Of course when the profileplot command exits (either successfully or unsuccessfully), the original data is restored automatically by Stata.

      You could look at the code and use it as a basis for creating and tailoring the plots to your liking.

      Comment

      Working...
      X