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]

st: RE: Automatic report writing: Strings to Excel


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: Automatic report writing: Strings to Excel
Date   Fri, 27 Apr 2012 17:17:18 +0100

You need to trap long label names: 

if <the variable label is too long> { 
	<use the variable name> 
}
else <use the variable label> 

Nick 
[email protected] 


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Renger van Nieuwkoop
Sent: 27 April 2012 17:09
To: [email protected]
Subject: st: Automatic report writing: Strings to Excel

Hi
I want to do the following: I have a list with variables like E01, E02, ... etc. and labels "Food" "Tobacca Alcohol", etc.
I have written a script that produces for every variable (I have about 77) a summary with mean, quantils, median, kurtosis, etc. and moves it to a matrix.
The matrix is then send to excel using xml_tab. I use the variable names as rownames as it is impossible to add strings to the matrix

My goal: I want to replace the variable names by the labels because the variable names are not very practical for a report. 
The problem is that the label is sometimes too long  and I get an error message (for example: Monetaere_Transferausgaben_an_andere_Haushalte  invalid name).
I do not want to rename the variable names by hand, because then it wouldn't be an automatic script anymore.

Any idea how to solve this?

Renger

Here is (part of) my script:


matrix variablen =J(`numbervar',11,.)
matrix colnames variablen = mean sd min max p5 p25 median p75 p95 skewness kurtosis
scalar counter = 0

local variablenliste
foreach var of varlist _all {
   local variablenliste `variablenliste' `var'
   }

local variablenbez
foreach var of varlist _all {
   local varlabel : variable label  `var'
   local variablenbez `variablenbez' `var' `varlabel'
}

foreach v of varlist  `variablenliste'{
   scalar counter = counter + 1
   tabstat `v' [aweight=Gewicht], stat(mean sd min max p5 p25 median p75 p95 skewness kurtosis) format(%12.2f) save
   matrix varresults = r(StatTotal)
   forvalues i = 1/11   {
      matrix variablen[counter,`i'] = varresults[`i',1]
      }
   }
matrix rownames variablen = `variablenbez'
xml_tab variablen, save(summary_variablen.xml) sheet(Variablen) replace


____________________
Modelworks
Gewerbestrasse 15
3600 Thun - Switzerland
+41 79 818 53 73
[email protected]
blog.modelworks.ch



*
*   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