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

Re: st: collapse panel data for each year


From   "Dev Vencappa" <lexdvv@nottingham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   Re: st: collapse panel data for each year
Date   Fri, 28 May 2004 16:50:41 +0100

collapse sum(whatevervariable), by (country year)

not work? (I am assuming you will sum the industries values when collapsing the panel.


>>> sarah22209@hotmail.com 05/28/04 04:46pm >>>
Dear Stata users:

I have panel data for several industries in 40 countries for 20 years. For 
each year, I am trying to collapse the data by country. I tried to use 
foreach and forvalues commands, but could not work it out. I would 
appreciate if you can help me.

Thnks,
sarah





>From: "Nick Cox" <n.j.cox@durham.ac.uk>
>Reply-To: statalist@hsphsun2.harvard.edu 
>To: <statalist@hsphsun2.harvard.edu>
>Subject: st: RE: retrieving a three-letter word from a string variable
>Date: Fri, 28 May 2004 16:04:51 +0100
>
>One way to do this is
>
>gen whatever = "HMV" if index(myvar, "HMV")
>
>If you're fond of -cond()- you might prefer
>
>gen whatever = cond(index(myvar, "HMV"), "HMV", "")
>
>Neither is a retrieval solution, but the
>result is the same.
>
>Another way to do it is through retrieval:
>
>gen whatever = substr(myvar,index(myvar, "HMV"),3)
>	if index(myvar, "HMV")
>
>but I can't see any advantage to that.
>
>Nick
>n.j.cox@durham.ac.uk 
>
>Dev Vencappa
>
> >  I have a dataset that contains several string variables.
> > Suppose one string variable contains the following values in
> > one of the observations:
> >
> > CMLST(HMV)
> >
> > Another string variable contains :
> >
> > COMSTL  GTRI(HMV)
> >
> > I want stata to create a new variable that retrieves only the
> > three-letter word "HMV" from the string variable. I
> > understand that the substr command does that but because the
> > starting point of the word HMV is not the same for every
> > variable , it would be difficult to identify the correct
> > starting position to read the string and retrieve the first
> > three letters HMV.
> > Can somebody help please? I have tried the other string
> > commands but could not understand one that does what I want.
>
>*
>*   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/ 

_________________________________________________________________
Get 200+ ad-free, high-fidelity stations and LIVE Major League Baseball 
Gameday Audio! http://radio.msn.click-url.com/go/onm00200491ave/direct/01/ 

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


This message has been scanned but we cannot guarantee that it and any
attachments are free from viruses or other damaging content: you are
advised to perform your own checks.  Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index