Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: listing variable values


From   Eric Booth <[email protected]>
To   "<[email protected]>" <[email protected]>
Subject   Re: st: listing variable values
Date   Sat, 31 Jul 2010 22:11:14 +0000

<>

-outtable- expects to find a variable named r2 so you could use -mat rownames- to give it varnames it won't choke on.  
Just a warning that I'm not a latex or -outtable- user--I would probably do this with -tabout- (from SSC):
********************!
clear
global F5 "/Users/ida/Desktop//"
**
inp nace year turnover
1 1 1
1 2 1
1 3 4
1 10 10 
1 6 9
2 1 3
2 10 99
2 2 2
12 1 99
12 10 99
end
**
label var nace "Industry"
lab var year "Year"
lab var turnover "Turnover"

//1. using outtable//
mkmat nace turnover if year==1, matrix(X)
mkmat turnover if year==10, matrix(Y)
matrix Z=X,Y
mat li Z
mat rownames Z=n y t    // this should help you avoid the "r2" error
outtable using "$F5/table1",mat(Z) replace norowlab label caption("Turnover")
**

//prepare/reshape  data for use with listtex//
preserve
g id = _n
reshape wide turnover, i(id) j(year)
drop id
order nace
keep nace turnover1 turnover10
foreach v in turnover1 turnover10 {
bys nace: egen m`v' = max(`v')
replace `v' = m`v'
drop m`v'
} 
bys nace: g o = 1==_n
drop if o!=1
drop o

//2. using listtex//
cap which listtex
if _rc ssc install listtex, replace
listtex nace turnover1 turnover10  using "$F5/test.tex" ,  /*
*/  replace type rstyle(tabular) head("\begin{tabular}{rrr}"  /*
*/  "\textit{INDUSTRY}&\textit{TURNOVER YEAR 1}&\textit{TURNOVER YEAR 10}\\\\") /*
*/  foot("\end{tabular}")

//3. using tabout//
cap which tabout
if _rc ssc install tabout, replace
tabout nace using "$F5/test2.tex", replace sum c(max turnover1 max turnover10) /* 
*/  f(0c 0c 0c) ptotal(none) style(tex) lines(double) h1(| Turnover)   /* 
*/   topf(top.tex) botf(bot.tex) 

**You can get the top and bottom tex files & more on tabout from:  http://www.ianwatson.com.au/stata/tabout_tutorial.pdf
restore        

********************!
Watch for message wrapping.  I'm sure there's a faster way to prep the data for use with -listtex- , but this seems to work.


~ Eric

__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754



On Jul 31, 2010, at 11:42 AM, Ida Johnsson wrote:

> Hi!
> I have the following problem. I have a variables for different industries in long form (industry variable NACE and time variable year) and would like to create a latex table in which the columns would be values for selected variables for selected years, for example:
> 	
> Column 1	Column 2			Column 3
> Industry		Turnover Year 1 		Turnover Year 10
> 	10			1					2
> 	11			3					5
> 	12			4					4
> 
> etc...
> 
> 
> My idea was to create a matrixes with variables values in the columns
> 
> mkmat nace Turnover if year==1, matrix(X)
> 
> mkmat Turnover if year==10, matrix(Y)
> 
> matrix Z=X,Y
> 
> and then export them to latex using estout, esttab or outtable. However, when I tried
> 
> outtable using "/Users/ida/Desktop/table1",mat(Z) replace label norowlab caption("Turnover")
> 
> I got the message "variable r2 not found". The variable Industry has labels, which I would like to be displayed instead of the numerical values, and I'd also like to suppres the row names of the matrix (r1, r2 ... ). I have the feeling that creating a matrix to export variable values to latex is a somewhat roundabout way. Is it possible to use listtex to list values of the same variable but for different years in separate columns?
> 
> I will be vary grateful for all help.
> 
> Regards,
> Ida
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/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/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index