Hi all, I have had no luck with my research as I have been unable to loop these commands properly as my postfile wont work - if anyone would be able to tell me what was failing please let me know - *Generate helper variable
gen ipc3 = substr(ipc4, 1, 3)
gen country = substr(nuts3, 1, 2)
gen ipc2 = substr(ipc4, 1, 2)
*Sum patents by country-region-year
collapse (sum) sh_pat, by(country nuts3 ipc2 year)
*Total patents per country-year
bysort country ipc2 year: egen tot_pat_cpt = total(sh_pat)
*Region share of tp (within country-year)
gen share_region = sh_pat / tot_pat_cpt
egen cod_tech=group(country ipc2)
* STEP 2: Theil and Gini Indices
preserve
tempfile tgresults
tempname tgpost
postfile `tgpost' double cod_tech int year double theil gini using `tgresults', replace
levelsof cod_tech, local(countries)
levelsof year, local(years)
foreach c of local countries {
foreach y of local years {
keep if cod_tech == `c' & year == `y'
qui count if share_region > 0
if r(N) >= 2 {
qui ineqdeco share_region
local gini = r(gini)
local theil = r(ge1)
}
else {
local gini = .
local theil = .
}
post `tgpost' (`c') (`y') (`theil') (`gini')
restore, preserve
}
}
postclose `tgpost'
use `tgresults', clear
save theil_gini_cod_tech.dta, replace
restore
it returns the following error wrt the postfile failure - [P] error . . . . . . . . . . . . . . . . . . . . . . . . Return code 198
invalid syntax
option __________ incorrectly specified
option __________ not allowed
__________ invalid
range invalid
__________ invalid obs no
invalid filename
__________ invalid varname
__________ invalid name
multiple by's not allowed
__________ found where number expected
on or off required
All items in this list indicate invalid syntax. These errors
are often, but not always, due to typographical errors. Stata
attempts to provide you with as much information as it can.
Review the syntax diagram for the designated command.
In giving the message "invalid syntax", Stata is not helpful.
Errors in specifying expressions often result in this message.
(end of search)
gen ipc3 = substr(ipc4, 1, 3)
gen country = substr(nuts3, 1, 2)
gen ipc2 = substr(ipc4, 1, 2)
*Sum patents by country-region-year
collapse (sum) sh_pat, by(country nuts3 ipc2 year)
*Total patents per country-year
bysort country ipc2 year: egen tot_pat_cpt = total(sh_pat)
*Region share of tp (within country-year)
gen share_region = sh_pat / tot_pat_cpt
egen cod_tech=group(country ipc2)
* STEP 2: Theil and Gini Indices
preserve
tempfile tgresults
tempname tgpost
postfile `tgpost' double cod_tech int year double theil gini using `tgresults', replace
levelsof cod_tech, local(countries)
levelsof year, local(years)
foreach c of local countries {
foreach y of local years {
keep if cod_tech == `c' & year == `y'
qui count if share_region > 0
if r(N) >= 2 {
qui ineqdeco share_region
local gini = r(gini)
local theil = r(ge1)
}
else {
local gini = .
local theil = .
}
post `tgpost' (`c') (`y') (`theil') (`gini')
restore, preserve
}
}
postclose `tgpost'
use `tgresults', clear
save theil_gini_cod_tech.dta, replace
restore
it returns the following error wrt the postfile failure - [P] error . . . . . . . . . . . . . . . . . . . . . . . . Return code 198
invalid syntax
option __________ incorrectly specified
option __________ not allowed
__________ invalid
range invalid
__________ invalid obs no
invalid filename
__________ invalid varname
__________ invalid name
multiple by's not allowed
__________ found where number expected
on or off required
All items in this list indicate invalid syntax. These errors
are often, but not always, due to typographical errors. Stata
attempts to provide you with as much information as it can.
Review the syntax diagram for the designated command.
In giving the message "invalid syntax", Stata is not helpful.
Errors in specifying expressions often result in this message.
(end of search)
Comment