Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Index


From   A Loumiotis <antonis.loumiotis@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Index
Date   Thu, 12 Jan 2012 12:34:43 +0200

Hi Pavle,

The code below uses -tuples- written by Nicholas J. Cox and is from SSC.
It's a bit long but I think it does the job. I apologize if some lines
are truncated.

Best,
Antonis

clear all
input firm yr mkt msal
1         1990    1              1
1         1991    1              1
1         1992    2              .3
1         1992    2             .1
1         1992    3              .15
1         1992    2             .15
1         1992    3             .15
1         1992    4             .15
1         1993    4              .40
1         1993    4             .20
1         1993    5             .40
2         1990    1              1
2         1991    1              1
2         1992    2              .3
2         1992    2             .1
2         1992    3              .15
2         1992    2             .15
2         1992    3             .15
2         1992    4             .15
2         1993    4              .40
2         1993    4             .20
2         1993    5             .40
end

gen index=.
sum firm, meanonly
forvalues i=1/`r(max)' {
	sum yr, meanonly
	forvalues j=`r(min)'/`r(max)' {
		preserve
		keep if firm==`i' & yr==`j'
		if `=_N'==1 local index`i'`j' msal[1]
		else {
			local index`i'`j'=0
			forvalues k=1/`=_N' {
				local mo`i'`j' "`mo`i'`j'' `k'"
				local m`i'`j'`k'=mkt[`k']
				local ms`i'`j'`k'=msal[`k']
			}
			tuples `mo`i'`j'', max(2)
			forvalues l=1/`ntuples' {
				if `:list sizeof tuple`l''==2 {
					local mtuple`l' "`m`i'`j'`:word 1 of `tuple`l'''' `m`i'`j'`:word
2 of `tuple`l''''"
					if "`:list dups mtuple`l''"=="" local
index`i'`j'=`index`i'`j''+2*(`ms`i'`j'`:word 1 of
`tuple`l''''*`ms`i'`j'`:word 2 of `tuple`l'''')
					else local index`i'`j'=`index`i'`j''+`ms`i'`j'`:word 1 of
`tuple`l''''*`ms`i'`j'`:word 2 of `tuple`l''''
				}
			}
		}
		restore
		replace index=`index`i'`j'' if firm==`i' & yr==`j'
	}	
}
format index %4.2g
list
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index