Bookmark and Share

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

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

st: 2 questions on function wordcount

From   "Impavido, Gregorio" <>
To   "STATALIST (" <>
Subject   st: 2 questions on function wordcount
Date   Thu, 3 May 2012 12:34:34 -0400

Dear all,

The following two examples should give the same result but they don't.

/*-------begin 1 ---------*/
unab vlist : *
di wordcount(`"`vlist'"')
/*-------end 1 ---------*/

/*-------begin 2 ---------*/
unab vlist : *
local i 0
foreach var of local vlist {
	local i = `i' + 1
di `i'
/*-------end 2 ---------*/

In my case, wordcount gives me a different result depending on how I rename the variables in the dataset while the second gives me always 170 (which happens to be the number of variables in the dataset.

Question 1. Is this related to the length limitation of the local macro? But if Yes, why is the macro vlist not truncated?

Question 2. Is there a quicker way to do display the last word in vlist (i.e., -di word((`"`vlist'"',wordcount(`"`vlist'"'))-) than using example 2 above to extract the number of the last variable?

Thank you in advance for your help

*   For searches and help try:

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