Dear all,
I hope you are all doing great.
I am trying to calculate the ttest of x (total dollar's placement) by y (with 1 = inside the US and 0 = outside the US) over the period 1995 and 2000.
I tried the following code:
By doing so, I found the result. Nonetheless, I need to calculated the mean of x for each y (1 & 0) scaled by the total x for the period above 1998 & the period below 1998. So it would give us ((mean x before 1998) - (mean x after 1998) / (total mean over period)) for each y. So we would get 4 means in total.
I did the following but the ttest at the end does not work and I find the code too long. Is there any way to solve the ttest (t-statistics = .) and to reduce the length?
Thanks in advance,
Eugene
I hope you are all doing great.
I am trying to calculate the ttest of x (total dollar's placement) by y (with 1 = inside the US and 0 = outside the US) over the period 1995 and 2000.
I tried the following code:
Code:
ttest x, by(y)
Code:
egen mean_1 = mean(x) if year <= 1998 & y == 1 fillmissing mean_1, with(any) egen mean_2 = mean(x) if year > 1998 & y == 1 fillmissing mean_2, with(any) egen mean_3 = mean(x) gen x_1 = ((mean_1-mean_2)/mean_3) egen mean_11 = mean(x) if year <= 1998 & y == 0 fillmissing mean_11, with(any) egen mean_12 = mean(x) if year > 1998 & y == 0 fillmissing mean_12, with(any) gen x_2 = ((mean_11-mean_12)/mean_3) gen Pre_Post = . replace Pre_Post = x_1 if y == 1 replace Pre_Post = x_2 if y == 0 ttest Pre_Post, by(y)
Thanks in advance,
Eugene
Comment