Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: creating a macro from tabulate


From   Gijs Dekkers <[email protected]>
To   [email protected]
Subject   st: creating a macro from tabulate
Date   Mon, 24 Oct 2005 14:41:57 +0200

Dear all,

I guess this again is a simple question, but I cannot find the answer, so here we go. Suppose I do a tabulate of a variable vname

.tabulate vname

and the result is

vname Freq. Percent Cum.
-8 2,922 6.49 6.49
1 12,586 27.96 34.45
2 13,628 30.28 64.73
3 15,877 35.27 100.00
Total 62,449 100.00

Now I want to create a variable Y which has the same frequency structure as "vname". The below piece of code works fine...

generate x=uniform()*100
.generate y=-8 if x<6.49
.replace y=1 if (x>6.49 & x<34.45)
.replace y=2 if (x>34.45 & x<64.73)
.replace y=3 if (x>64.73 & x<100)

...though I am convinced that it could be done more efficient than I have done it. But that's not the point: my problem is that I have inputted the cumulative frequencies of the TABULATE (i.e., 6.49, 34.45, 64.73) directly into the above commands. This is no good, for any change of the cumulative frequencies would require changing of the whole code by hand.

So, how does one bring the cumulative frequencies of a TABULATE in a local macro, analogous to r(mean) or r(p50) in SUMMARY?

Many thanks!

Gijs

--
dr. Gijs Dekkers
Attach� Federal Planning Bureau
Kunstlaan 47-49
1000 Brussels, Belgium
++32/(0)2/5077413
fax 7373
[email protected], [email protected]



**********************************************************************
Disclaimer: This e-mail may contain confidential information
which is intended only for the use of the recipient(s) named above.
If you have received this communication in error, please
notify the sender immediately and delete this e-mail from
your system.
Please note that e-mail messages cannot be considered as official
information from the Federal Planning Bureau.
**********************************************************************
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index