Re: st: RE: last variable in the dataset

I think using `r(varlist)' rather than r(varlist) could work with a
larger data set:
describe, short varlist
local lastvar : word `r(k)' of `r(varlist)'
By the way, I'm not sure why word("`r(varlist)'", -1) isn't working
for me for large data sets...
A Mata solution could be st_varname(st_nvar()).
On Sat, Aug 13, 2011 at 6:20 PM, Mauro Mastrogiacomo
<M.Mastrogiacomo@cpb.nl> wrote:
> Ricardo, if the dataset is not too large you can use
> des, varlist
> local myvars=r(varlist)
> dis "`myvars'"
> This produces a macro with all variables names. You can then extract the last one.
> However if there are too many variables this trick will not work.
> Last Monday Nick posted a different solution to a similar problem (comparing datasets), you might want to have a look at that (unfortunately I don't remember his answer entirely).
> One other option is to use the command order and decide yourself which is the last variable, so that you don't need to find that out.
> Hope this helps a little.
> Mauro
>
> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Ricardo Ovaldia
> Sent: zaterdag 13 augustus 2011 17:07
> To: statalist@hsphsun2.harvard.edu
> Subject: st: last variable in the dataset
>
> Hello,
>
> I am writing an -ado- program that merges several datasets with different variables. I need to know the name of the last variable after the merge.
> Is there a way to get the name of the last variable or refer to the last variable in the dataset?
>
> Thank you,
> Ricardo
>
> Ricardo Ovaldia, MS
> Statistician
> Oklahoma City, OK
>
>
> *
> * 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/
>
> --
> ================================================================================
> Dit bericht kan informatie bevatten die niet voor u is bestemd. Indien u niet
> de geadresseerde bent of dit bericht abusievelijk aan u is toegezonden, wordt
> u verzocht dat aan de afzender te melden en het bericht te verwijderen.
> De Staat aanvaardt geen aansprakelijkheid voor schade, van welke aard ook, die
> verband houdt met risico's verbonden aan het elektronisch verzenden van
> berichten.
>
> This message may contain information that is not intended for you. If you are
> not the addressee or if this message was sent to you by mistake, you are
> requested to inform the sender and delete the message. The State accepts no
> liability for damage of any kind resulting from the risks inherent in the
> electronic transmission of messages.
> ================================================================================
>
> *
> * 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/
>
--
Matthew White
Evaluation Coordinator
Urban Micro-Insurance Project
Innovations for Poverty Action
+254 (0)701 025 276
mwhite@poverty-action.org
*
* 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/