Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Pradipto Banerjee <pradipto.banerjee@adainvestments.com> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | st: RE: RE: assigning a specific row as a local variable |
Date | Mon, 1 Oct 2012 18:08:34 -0500 |
Thanks, David. I wanted to assign the value to local macro `x' instead of a variable `x'. Actually, I have found a program -valuesof- which is pretty much what I was looking for. -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of David Radwin Sent: Monday, October 01, 2012 7:01 PM To: statalist@hsphsun2.harvard.edu Subject: st: RE: assigning a specific row as a local variable There's no such thing as a "local variable" in Stata. I think you want a -tempvar- (temporary variable with a local macro name). First you declare the -tempvar-, then you use it. Based on your description, I would create two -tempvars-. In this example, n = 2. . tempvar x . tempvar cond_y_sum . gen `cond_y_sum' = sum(cond_y) // creates cumulative sum of values where cond_y equals 1 . gen `x' = y if `cond_y_sum' == 2 // assigns value of y to `x' for the nth observation where y equals 1 David -- David Radwin Senior Research Associate MPR Associates, Inc. 2150 Shattuck Ave., Suite 800 Berkeley, CA 94704 Phone: 510-849-4942 Fax: 510-849-0794 www.mprinc.com > -----Original Message----- > From: owner-statalist@hsphsun2.harvard.edu [mailto:owner- > statalist@hsphsun2.harvard.edu] On Behalf Of Pradipto Banerjee > Sent: Monday, October 01, 2012 3:35 PM > To: statalist@hsphsun2.harvard.edu > Subject: st: assigning a specific row as a local variable > > Hi, > > I want to define a local variable x as the nth value of a column y that > satisfies a particular condition. > > More specifically, suppose I have y and cond_y as follows: > > y cond_y > > 1 1 > 3 0 > 1 0 > 2 1 > 4 1 > > I want to assign > > local x = y if "y is say the 2nd value where cond_y is true" > > How can I achieve this? > > Thanks. * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/ This communication is for informational purposes only. It is not intended to be, nor should it be construed or used as, financial, legal, tax or investment advice or an offer to sell, or a solicitation of any offer to buy, an interest in any fund advised by Ada Investment Management LP, the Investment advisor. Any offer or solicitation of an investment in any of the Funds may be made only by delivery of such Funds confidential offering materials to authorized prospective investors. An investment in any of the Funds is not suitable for all investors. No representation is made that the Funds will or are likely to achieve their objectives, or that any investor will or is likely to achieve results comparable to those shown, or will make any profit at all or will be able to avoid incurring substantial losses. Performance results are net of applicable fees, are unaudited and reflect reinvestment of income and profits. Past performance is no guarantee of future results. All f! inancial data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of Ada Investment Management LP and its affiliates. This transmission may contain information that is confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is strictly prohibited. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/