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

[no subject]



NumFirms: gives the number of firms for each sector
IP1 until IP67: deflators  
IPUsado: the number of the deflator used for each sector

In another dataset (main dataset), I have some variables ordered by
Sector, Firm, Year

I would like to build a column containing all the deflators used in 
order to merge it with my main dataset.


A simplified subset of my dataset of IPS would look like:

NumFirms  IP1   IP2  ... IP67     IPUsado

2         1     1         1          2
4         1.23  1.12      1.08       1
3          1.45  1.23      1.12      67
.         1.50  1.34      1.16       2 
.         1.53  1.43      1.23       1

I need to create a new variable which would look like:

IP

1        
1.12        
1.23          this is the IP2 used for the first firm of the first 
1.34          sector  
1.43  
1        
1.12        
1.23          this is the IP2 used for the second firm of the first 
1.34          sector  
1.43  
1     
1.23  
1.45          this is the IP1 used for the first firm of the
1.50          second sector
1.53 


...


1     
1.23  
1.45          this is the IP1 used for the last(3rd) firm of the
1.50          last sector
1.53 

Should anyone find another possibility to accomplish that aim, I would be 
very glad to learn it.
 
I had already succeeded in creating the variable by using the following 
approach. It is really a na�ve one but faster than a nested sequence of fors 
as Mr Winter has warned me.

____________________________________________________________________________
clear
set more off
local deflator="C:\DATA\RJ\def_96.dta" /*the name of the file containing the 
      deflators*/
local num_anos=5 /*number of years*/
use `deflator' 
local q=0
foreach var of varlist _all { 
use `deflator' 
local q=`q'+1
keep `var'
ren `var' var1
save ip`q'.dta, replace}
use "C:\DATA\RJ\Concatena_Oficial.dta", clear /*dataset which contains 
IPUsado and NumF*/
gen parmer=_n
local varMer=NumFirms[1]*`num_anos' /*para nao ter missing na primeira*/
local IPF1=IPUsado[1]
sort parmer
save "C:\DATA\RJ\Col_IP_oficial.dta", replace
su NumFirms, meanonly
local Tot_set=r(N)
set obs `varMer'
cd C:\DATA
merge using  ip`IPF1'.dta
drop _merge parmer
ren var1 var2
local step1=var2[1]
local step2=var2[2]
local step3=var2[3]
local step4=var2[4]
local step5=var2[5]
egen var1=fill( `step1' `step2' `step3' `step4' `step5' `step1' `step2' 
`step3' `step4' `step5')
drop var2
forvalues sector=2 3 to `Tot_set' {
        local Tot_Firm=NumFirms[`sector']   
        local IP=IPUsado[`sector']      
        forvalues firm=1 2 to `Tot_Firm' { 
               append using"c:\Data\ip`IP'.dta" 
        }
}

____________________________________________________________________

I am new to Stata, and I am meaning to use it as much as possible,
thanks again for the attention,
Euler

Ps.:A matlab code to achieve the same result would be sth like:  

Super=[];
for i=1:size(NumFirms,1)
   Super=[Super; repmat(IPA(:,IPUsado(i,1)),NumFirms(i,1),1)];
end
clear i

but I do not feel like changing packages every time I need to solve a problem.


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