-2

I am trying to do a t test for values I stored in scalars that I extracted from a regression analysis on panel data-set (see sample code A). but Stata is not allowing me to use the scalar names as variable names (error:'Type7df' found where integer expected). Is there a way to use the scalar values instead of their names?

. display Type7df
3506

. display Type7b
-.14521431

. display Type7se
.05345269

. display Type8df
3403

. display Type8b
-.00643857

. display Type8se
.06156362

**. ttesti Type7df Type7b Type7se Type8df Type8b Type8se

Resulted in the error:

'Type7df' found where integer expected

r(7);**

Sample code 1:

xtreg maxofact NCLB Asian_P White_P Black_P Hispanic_P economic_P atRisk_P teachers_P funds if types ==7, fe
estimates store fixed7, title(Non-Metro: Stable)
matrix Type7Mx = r(table)
matrix list r(table)
scalar Type7b  = Type7Mx[1,1]
scalar Type7se = Type7Mx[2,1]
scalar Type7df = Type7Mx[7,1]
....
Nick Cox
  • 35,529
  • 6
  • 31
  • 47
OAM
  • 73
  • 2
  • 2
  • 7
  • 1
    Various confusions here. (1) In Stata, scalars do not qualify as variables; if you want to think of them as variables because that is your personal programming terminology, that's fine for you, but does not match Stata concepts. (2) The `ttesti` command you are using does not expect variables to be named; it expects numeric arguments. Hence the report that Stata won't allow use of scalars as if they were variables misses the point; the problem here is that `ttesti` won't evaluate scalars for you. @Dimitriy V. Masterov's answer shows how to ensure that `ttesti` sees numeric arguments. – Nick Cox Dec 17 '14 at 10:31
  • (I edited out minor slips but comment above on the more notable confusions.) – Nick Cox Dec 17 '14 at 10:33

1 Answers1

4

You need to dereference the scalar. Here's an example:

sysuse auto, clear
sum price 
scalar obs = r(N)
scalar mean = r(mean)
scalar sd = r(sd)
scalar value  = 10000
ttesti `=obs' `=mean' `=sd' `=value'

ttest price=10000

However, if you just want to test coefficients, why not do that directly?

dimitriy
  • 9,077
  • 2
  • 25
  • 50
  • I am comparing different groups regressions betas to see if a change after a certain event is different for different groups. so I am running different regression for each group and then comparing the betas of the event dummy to see if the event had different effect on each group. I am sure that there are better ways to that. Someone suggested the use of contrast and margins to help me evaluate the impact analysis and I am currently looking into it... thank you again... – OAM Dec 17 '14 at 18:50