--- "Issam.Hallak" <[email protected]> wrote:
> My dataset looks like this:
>
> company_name year var1 var2 var3 ...
>
> firm_A 1990 3 2 5 ...
> firm_A 1991 4 2.4 4.8 ...
> firm_A 1992 4.2 3 5 ...
> ... ... ... ... ... ...
> firm_B 1990 2 1.5 4 ...
> firm_B 1991 2 1.6 4.1 ...
> ... ... ... ... ... ...
> all_firms 1990 30 50 56 ...
> all_firms 1991 32 61 87 ...
> ... ... ... ... ... ...
>
> For each firm, I wish to generate a new variable that uses the values
>
> of all_firms. For instance:
>
> var_10 = var1{firm_A;1990}/var1{all_firms;1990}
The trick here is to use the -reshape- command. Furthermore, as you
probably have many firms I automated the computation by creating list
of all firm in your data with the -levelsof- command (and extracting
the level "all_firms") and looping over them. See the example below:
*----------------- begin example --------------
drop _all
input str9 company_name year var1 var2 var3
firm_A 1990 3 2 5
firm_A 1991 4 2.4 4.8
firm_B 1990 2 1.5 4
firm_B 1991 2 1.6 4.1
all_firms 1990 30 50 56
all_firms 1991 32 61 87
end
levelsof company
local allfirms "all_firms"
local alllevs `"`r(levels)'"'
local levs : list alllevs - allfirms
di `"levs'"'
reshape wide var1 var2 var3, i(year) j(company) string
foreach lev of local levs{
gen var10`lev' = var1`lev' / var1all_firms
}
reshape long var1 var2 var3 var10, i(year) j(company) string
*------------------ end example ---------------
(For more on how to use examples I sent to the Statalist, see
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )
Hope this helps,
Maarten
-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands
visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434
+31 20 5986715
http://home.fsw.vu.nl/m.buis/
-----------------------------------------
___________________________________________________________
Yahoo! Answers - Got a question? Someone out there knows the answer. Try it
now.
http://uk.answers.yahoo.com/
*
* 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/