Hi all,
Ousmane has recently raised a problem using povdeco.
In fact, his program crashes when egen is invoked.
In his code, all previous egen calculus went fine expect for a special
sum to be computed.
I was able to reproduce the problem using auto data.
However, I am not a so good programmer, so I seek the community's
help.
Suppose we have the fancy sum to compute. Here is the result.
. clear
. sysuse auto
(1978 Automobile Data)
. se tr on
.
.
. egen sume = sum(gear_ratio*displacement*length)/displ[1] , by(for)
-----------------------------------------------------------------------------------------
begin egen ---
- version 6
- gettoken type 0 : 0, parse(" =(")
- gettoken name 0 : 0, parse(" =(")
- if`"`name'"'=="=" {
= if`"="'=="=" {
- local name `"`type'"'
= local name `"sume"'
- local type : set type
- }
- else {
gettoken eqsign 0 : 0, parse(" =(")
if `"`eqsign'"' != "=" {
error 198
}
}
- confirm new variable `name'
= confirm new variable sume
- gettoken fcn 0 : 0, parse(" =(")
- gettoken args 0 : 0, parse(" ,") match(par)
- if `"`par'"' != "(" {
= if `"("' != "(" {
exit 198
}
- if `"`args'"' == "_all" {
= if `"gear_ratio*displacement*length"' == "_all" {
version 7.0
unab args : _all
local args : subinstr local args "`_sortindex'" "", all word
version 6.0
}
- syntax [if] [in] [, *]
varlist not allowed
-------------------------------------------------------------------------------------------
end egen ---
r(101);
I do not why the last syntax is not going through.
And I do not have the programming
manual to find a solution.
Best regards.
Amadou Bassirou DIALLO.
PS: This calculus works fine.
. egen meany = sum(gear_rat*displ) , by(for)
-----------------------------------------------------------------------------------------
begin egen ---
- version 6
- gettoken type 0 : 0, parse(" =(")
- gettoken name 0 : 0, parse(" =(")
- if`"`name'"'=="=" {
= if`"="'=="=" {
- local name `"`type'"'
= local name `"meany"'
- local type : set type
- }
- else {
gettoken eqsign 0 : 0, parse(" =(")
if `"`eqsign'"' != "=" {
error 198
}
}
- confirm new variable `name'
= confirm new variable meany
- gettoken fcn 0 : 0, parse(" =(")
- gettoken args 0 : 0, parse(" ,") match(par)
- if `"`par'"' != "(" {
= if `"("' != "(" {
exit 198
}
- if `"`args'"' == "_all" {
= if `"gear_rat*displ"' == "_all" {
version 7.0
unab args : _all
local args : subinstr local args "`_sortindex'" "", all word
version 6.0
}
- syntax [if] [in] [, *]
- if _by() {
local byopt "by(`_byvars')"
local cma ","
}
- else if `"`options'"' != "" {
= else if `"by(for)"' != "" {
- local cma ","
- }
- tempvar dummy
- global EGEN_Varname `name'
= global EGEN_Varname meany
- capture noisily _g`fcn' `type' `dummy' = (`args') `if' `in' `cma' `byopt'
`options'
= capture noisily _gsum float __000001 = (gear_rat*displ) , by(for)
--------------------------------------------------------------------------------------
begin _gsum ---
- version 6
- syntax newvarname =/exp [if] [in] [, BY(varlist)]
- tempvar touse
- quietly {
- gen byte `touse'=1 `if' `in'
= gen byte __000002=1
- sort `touse' `by'
= sort __000002 foreign
- by `touse' `by': gen `typlist' `varlist' = sum(`exp') if `touse'==1
= by __000002 foreign: gen float __000001 = sum((gear_rat*displ) ) if
__000002==1
- by `touse' `by': replace `varlist' = `varlist'[_N]
= by __000002 foreign: replace __000001 = __000001[_N]
- }
----------------------------------------------------------------------------------------
end _gsum ---
- global EGEN_Varname
- if _rc { exit _rc }
- quietly count if missing(`dummy')
= quietly count if missing(__000001)
- if r(N) {
local s = cond(r(N)>1,"s","")
di in bl "(" r(N) " missing value`s' generated)"
}
- rename `dummy' `name'
= rename __000001 meany
-------------------------------------------------------------------------------------------
end egen ---
*
* 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/