I am trying to achieve the following: I want to access a number from a table in the main text and make some calculations with it. For example, if there is a value 1.85 in the table I want to store it under a variable name and be able to call it in the main text which then generates 1.85.
The MWE below shows some code kindly provided by egreg that stores a value from a table under a command name. This works quite well if I "hard code" the label manually into the table. The problem is that tables are automatically generated so I can't write \setvalue{\ValueA}{20} in the table because it would disappear the next time the table is generated.
The layout of the table hardly ever changes, only the numbers change. So what I would need is some "grid search" that takes the value from a cell that I have manually specified and wraps it automatically into egregs code, e.g. The value is \setvalue\ValueC{mytable.tex}{2}{7} would access column 2, row 7 of mytable. Is something like that possible, or are there better solutions?
Another issue is that I can't access values before the table has been included (see the first commented line). I guess one possible solution would be to put all tables into an insivible box at the beginning of the document, but maybe there a better ways.
The MWE below shows how tables generated by Stata's estout typically look like. mytable.tex only contains the bare content of the table which is then wrapped into the table environment by the \estauto command.
\documentclass{scrartcl}
\usepackage{booktabs,filecontents,lmodern,calculator,siunitx}
\sisetup{round-mode=places,round-precision=2}
\makeatletter
\newcommand{\setvalue}[2]{%
\@ifdefinable{#1}{\gdef#1{#2}}#2
}
\makeatother
\DeclareRobustCommand{\estauto}[3]{%
\vspace{.75ex}{%
\begin{tabular}{l*{#2}{#3}}%
\toprule%
#1%
\bottomrule%
\addlinespace[.75ex]%
\end{tabular}%
}
}
\begin{filecontents}{mytable.tex}
& \multicolumn{1}{c}{(1)} & \multicolumn{1}{c}{(2)} & \multicolumn{1}{c}{(3)} \\
\midrule
\emph{First Control Set} & & & \\
Variable 1 & \setvalue{\ValueA}{1.85} & \setvalue{\ValueB}{0.92} & 1.11 \\
& (0.34) & (0.24) & (0.14) \\
Variable 2 & 0.07 & 0.07 & 0.07 \\
& (0.01) & (0.02) & (0.01) \\
Variable 3 & -0.02 & -0.01 & -0.01 \\
& (0.01) & (0.00) & (0.00) \\
\end{filecontents}
\begin{document}
% This does not work because it calls the value before the table is included (\ValueA).
\begin{table}\centering\footnotesize
\caption{Consumer Credit Portfolios for Borrowers}
\label{tab:portfolio}
\estauto{\input{mytable.tex}}{3}{c}
\end{table}
This does work and the value is of Variable 1 in (1) is \ValueA{} and in
(2) \ValueB{}. %The spacing is not correct after the values are called.
Let's try some maths: The difference of (1) and (2) of Variable 1 is
\SUBTRACT{\ValueA}{\ValueB}\DiffAB \num{\DiffAB}
% package calculator also has a round option, but I don't really understand the syntax
\end{document}



;)– Claudio Fiandrino Nov 28 '12 at 17:21pgfplotstable:) – percusse Nov 28 '12 at 22:07