Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Andrea Bennett <mac.stata@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: change grouping in Stata -graph- command |

Date |
Fri, 31 May 2013 16:06:33 +0200 |

Thanks a lot Billy! I see what you do… But I still think Stata should provide a more obvious solution to this problem… Best, Andrea On May 31, 2013, at 15:59 , William Buchanan <william@williambuchanan.net> wrote: > Using the -by()- option will produce multiple graph regions in the same image. If the user wants things to appear that way, there are two different approaches that will yield equivalent results: > > 1.) Compute and store the summary statistics of interest for each group (I typically store the results in a matrix); -svmat- the matrix with the results; use the same graph command with the - (asis) - option before the variable names. > > 2.) Reshape the data set from wide to long format (e.g., store the responses in a single column vector and use an additional variable to identify the survey item of interest), then use two - over() - options to get the intended aesthetic: > > clear > set obs 100 > g byte treat=rbinomial(1,.5) /// Create a random treatment indicator > g loc = runiform() /// Generate a random uniform variable for location > sort loc /// Sort on the values of location > g price = runiform() /// Generate a random uniform variable for price > sort loc price /// Sort on the values of location and price > g temp = runiform() /// Generate a random uniform variable for temperature > foreach v of var loc price temp { > egen `v'_b = cut(`v'), group(7) /// Create new versions of the variables with 7 discrete values > drop `v' > } > rename (loc_b price_b temp_b)(v1 v2 v3) /// rename the variables to make it easier to reshape the data > g id = _n /// Generate individual IDs > reshape long v, i(id treat) j(var) /// Reshape the data and create a new variable 'var' that identifies the specific items (1 = Location; 2 = Price; 3 = Temperature) > gr bar v, over(treat) asyvar over(var) /// Generate the graph with the aesthetic that you wanted > > I tend to think the second method is a bit easier to use and makes it a bit easier to control some of the aesthetics if you're trying to create graphs that will be used in various publications or deliverables. There will be a gap between the items in the graph, but no gap between treatment and control groups (although treatment and control will each have their own color). > > HTH, > Billy > > > > On May 31, 2013, at 6:06 AM, Alexis Penot <alexis.penot@ens-lyon.fr> wrote: > >> Using by instead of over ? >> >> Alexis >> >> Le 31 mai 2013 à 14:58, Andrea Bennett <mac.stata@gmail.com> a écrit : >> >>> Hi there >>> >>> I've spent hours on the following issue but seem to be unable to find the correct way to deal with such a graph: >>> >>> I have questionnaire data where people are ask how much they liked some aspect; e.g. three variables LOCATION, PRICE, TEMPERATURE (all 1-7 scale). >>> >>> Both the treatment and control group filled in the same questionnaire. I want to see graphically how the treatment and control groups differ in above dimensions. >>> >>> The following produces the correct data but groups in a "wrong" way. The groups are divided into treated/not-treated: >>> >>> graph bar location price temperature, over(treated) >>> >>> However, I would like to have the following: >>> >>> Location - not treated >>> Location - treated >>> >>> [gap] >>> >>> Price - not treated >>> Price - treated >>> >>> [gap] >>> >>> Temperature - not treated >>> Temperature - treated >>> >>> I really don't see who I can produce this result. Options such as -asy- or -asc- seem to go into the right direction but are not producing the result I desire. I would think that this is a rather common feature but it seems utterly difficult to get. >>> >>> Any suggestions? >>> >>> Many thanks in advance, >>> >>> Andrea >>> >>> >>> >>> >>> * >>> * For searches and help try: >>> * http://www.stata.com/help.cgi?search >>> * http://www.stata.com/support/faqs/resources/statalist-faq/ >>> * http://www.ats.ucla.edu/stat/stata/ >> >> * >> * For searches and help try: >> * http://www.stata.com/help.cgi?search >> * http://www.stata.com/support/faqs/resources/statalist-faq/ >> * http://www.ats.ucla.edu/stat/stata/ > > > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/faqs/resources/statalist-faq/ > * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**Re: st: change grouping in Stata -graph- command***From:*Nick Cox <njcoxstata@gmail.com>

**References**:**st: change grouping in Stata -graph- command***From:*Andrea Bennett <mac.stata@gmail.com>

**Re: st: change grouping in Stata -graph- command***From:*Alexis Penot <alexis.penot@ens-lyon.fr>

**Re: st: change grouping in Stata -graph- command***From:*William Buchanan <william@williambuchanan.net>

- Prev by Date:
**st: Bar Graph Chart** - Next by Date:
**st: randomly drop duplicates** - Previous by thread:
**Re: st: change grouping in Stata -graph- command** - Next by thread:
**Re: st: change grouping in Stata -graph- command** - Index(es):