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

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

From |
Mauricio Esteban Cuak <cuak2000@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Making a bar graph from the row of a matrix |

Date |
Fri, 12 Apr 2013 17:37:36 -0500 |

Nick, Thanks for your help, your code looks much better. And yes, the code I sent was just for the list to know what I was doing. Best! ME 2013/4/8 Nick Cox <njcoxstata@gmail.com>: > Your runnable code made it easier to see what you are doing; thanks. > Presumably this is just an example we can all play with. > > -svmat- is a rather ugly command; the code here avoids it and adds a > couple of small tricks. > > More importantly, I suggest considering a -graph dot- command. With > more than a few predictors, which you may have in your real > application(s), it is likely to be easier to read the resulting graph. > > clear all > sysuse auto.dta > qui reg price mpg trunk weight > matrix test = e(V) > matrix rowtest = test["weight", 1...] > /* rowtest is the row I want to graph */ > gen var_colnames = "" > gen trans_rowtest = . > tokenize "`: colnames rowtest'" > qui forval i = 1/`= colsof(rowtest)' { > replace trans_rowtest = rowtest[1, `i'] in `i' > replace var_colnames = "``i''" in `i' > } > graph bar (asis) trans_rowtest, over(var_colnames) > graph dot (asis)trans_rowtest, over(var_colnames) /// > yli(0, lc(gs12) lw(vthin)) ytitle("coefficient") > > Nick > njcoxstata@gmail.com > > > On 8 April 2013 16:49, Mauricio Esteban Cuak <cuak2000@gmail.com> wrote: >> Hi Nick, thanks for the answer. >> The following code plots the graph I wanted and may be useful for other people. >> It doesn't look very nice however. >> As suggested by Nick, I moved the names into a variable (slightly >> tricky) and the values into another. >> >> >> /* Begin CODE */ >> >> clear all >> >> sysuse auto.dta >> >> qui reg price mpg trunk weight >> >> matrix test = e(V) >> >> >> matrix rowtest = test["weight", 1...] >> >> /* rowtest is the row I want to graph */ >> >> >> local names : colnames rowtest >> >> local n_names : word count `names' >> >> >> gen var_colnames = "" >> >> forval i=1/`n_names' { >> >> local this_name = "`:word `i' of `names''" >> >> replace var_colnames = "`this_name'" if _n == `i' >> >> } >> >> matrix trans_rowtest = rowtest' >> >> svmat trans_rowtest >> >> graph bar trans_rowtest1, over(var_colnames) >> >> >> ************************************** >> >> >> >> 2013/4/7 Mauricio Esteban Cuak <cuak2000@gmail.com> >>> >>> Hi Nick, thanks for the answer. >>> The following code plots the graph I wanted and may be useful for other people. >>> It doesn't look very nice however. >>> As suggested by Nick, I moved the names into a variable (slightly tricky) and the values into another. >>> >>> >>> **************BEGIN CODE******************** >>> >>> clear all >>> >>> sysuse auto.dta >>> >>> qui reg price mpg trunk weight >>> >>> matrix test = e(V) >>> >>> >>> matrix rowtest = test["weight", 1...] >>> >>> /* rowtest is the row I want to graph */ >>> >>> >>> local names : colnames rowtest >>> >>> local n_names : word count `names' >>> >>> >>> gen var_colnames = "" >>> >>> forval i=1/`n_names' { >>> >>> local this_name = "`:word `i' of `names''" >>> >>> replace var_colnames = "`this_name'" if _n == `i' >>> >>> } >>> >>> matrix trans_rowtest = rowtest' >>> >>> svmat trans_rowtest >>> >>> graph bar trans_rowtest1, over(var_colnames) >>> >>> >>> >>> >>> >>> >>> 2013/4/3 Nick Cox <njcoxstata@gmail.com> >>>> >>>> The easiest way to do this is probably to copy values from your matrix >>>> to a variable and then call up -twoway bar-. > * > * 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/

**References**:**Re: st: Making a bar graph from the row of a matrix***From:*Mauricio Esteban Cuak <cuak2000@gmail.com>

**Re: st: Making a bar graph from the row of a matrix***From:*Nick Cox <njcoxstata@gmail.com>

- Prev by Date:
**Re: st: Windows Environment Variable from the local system when running Stata via RemoteApp** - Next by Date:
**st: tsfill** - Previous by thread:
**Re: st: Making a bar graph from the row of a matrix** - Next by thread:
**Re: st: RE: how do we jointly test coefficients (fuller specification) from diff** - Index(es):