[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"David Harrison" <david.harrison@icnarc.org> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: How to transfer a variable's value into a macro (in a panel dataset) |

Date |
Mon, 28 Feb 2005 12:36:05 -0000 |

How I would go about setting up the dummys you describe is: gen byte f=. levels firmid, local(lev) foreach f of local lev { replace f=firmid==`f' bys year: egen byte firm_`f'=max(f) replace firm_`f'=firm_`f'-f } drop f (note: if you want firm_f to be 1 for all records with firmid f, then you don't need the -replace- statement above). I think this would be quicker than the approach you describe (which could be done with nested -levels- and -foreach- commands as described by Fred Wolfe). David -----Original Message----- From: Robin Luo [mailto:rluosf@gmail.com] Sent: 26 February 2005 05:28 To: statalist@hsphsun2.harvard.edu Subject: Re: st: How to transfer a variable's value into a macro (in a panel dataset) Sorry for the confusion. Let me explain the situation in more details: I have a variable called "firmid" and I generate a set of dummy variables from it. Now I need to use the value of the varialbe "firmid" to locate the dummy variables and do some calculations but the location part confuses me. Basically, my data has the following structure: firmid year firm_100 firm_101 firm_102 firm_103 firm_104 ...... 100 1980 101 1980 105 1980 121 1980 124 1980 101 1981 103 1981 196 1981 The data has been sorted by year and my goal is to check in each year which firms co-exist with a certain firm - for those coexisting, their respective dummy variables will be changed to 1 accordingly. For example, firm 100, 101, 105, 121, 124 coexist in 1980. Therefore, for the record where firmid=100 and year=1980, variables firm_101, firm_105 and likewise will be changed to 1. My plan is that for each year group check the values of "firmid" and then output these values to a local macro, which can be used to locate the corresponding firm dummy variables. But, as stated in my firm mail, I was stuck in how to do this macro set-up in a groupwise environment. Many thanks! Robin Luo * * 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/

- Prev by Date:
**st: barplot x-axis labels** - Next by Date:
**st: RE: barplot x-axis labels** - Previous by thread:
**Re: st: How to transfer a variable's value into a macro (in a panel dataset)** - Next by thread:
**st: GRQREG: Stata module to graph the coefficients of a quantile regression** - Index(es):

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