Student's t tests here make little sense without adjustment for time and space dependence structure, unless you have grounds for treating your data as equivalent to independent draws from the same distribution. You can do the tests, but standard errors and P-values are dubious if not bogus. That is, your individual tests on time series face one problem; and collectively your tests face another problem. For a good account, see either edition of Box, Hunter, Hunter, Statistics for experimenters. John Wiley.
That large point aside, Stata is choking on the []
which are being misread as an attempt to specify weights. My guess is that
by country: ttest x = `=x[54]' if year != 2013
would be acceptable syntax to Stata, although still dubious statistics. The detail here is the macro-like syntax
`= '
which has the effect that the expression given will be evaluated by Stata before the line is passed to ttest
. So the result, a numeric value, will be what the ttest
command sees.
This is naturally similar in spirit to what you were imagining, although your code is some way from being legal and correct.
UPDATE This calculation may also be helpful:
egen mean = mean(x / (year != 2013)), by(country)
egen sd = sd(x / (year != 2013), by(country)
gen z = (x - mean) / sd if year == 2013
list country x z if year == 2013