Statalist


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

st: RE: How to quickly generate variables by adding observations


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: RE: How to quickly generate variables by adding observations
Date   Wed, 13 Jan 2010 19:27:36 +0100

<>

Also see Nick`s http://www.stata-journal.com/article.html?article=pr0046

-egen, rowtotal()- allows you to specify a -varlist- which gives you access
to the shorthands assembled in [U], section 11.4.


*******
clear*

input yr  byte( abc_a  abc_b  abc_x  def_a  def_d)
1994 0 2 1 0 0
1995 0 0 1 2 0
1996 0 1 1 0 1
1997 0 1 0 1 0
1998 0 1 0 1 0 
end

compress

egen abc=rowtotal(abc_*)
egen def=rowtotal(def_*)

list, noobs 
*******


HTH
Martin


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Mike Kim
Sent: Mittwoch, 13. Januar 2010 19:19
To: [email protected]
Subject: st: How to quickly generate variables by adding observations

Dear all,

I would like to create the follwong variables from the following data:

gen abc=abc_a + abc_b + abc_x
gen def=def_a + def_d
......

  yr    abc_a  abc_b  abc_x  def_a  def_d
1994 0 2 1 0 0
1995 0 0 1 2 0
1996 0 1 1 0 1
1997 0 1 0 1 0
1998 0 1 0 1 0
......

The problem is that I have a lot of these variables that need to be 
generated in this way. Is there any easy way to generate them?

Thank you in advance.
Mike.

*
*   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/

*
*   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/



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