Question

I would like to perform a regression based on the interests of the user of the program.

For example I would like to run the following regression with the ability to change the inputs

reg prefers inSchool#female#treatment

I have multiple preference options for example math, science, arts, etc...

what i would like is something like

local preference = math (where I can choose the others as well)

local compareSchooling = Y
local compareGender = Y

reg preference inSchool#female#treatment

if compareSchooling=Y & compareGender=Y {
test 1.inSchool#1.female#1.treatment = 0.inSchool#0.female#1.treatment
}

The motivation behind this is that someone else can easily use the program to customize his/her analysis.

However, I have had a difficult time making the mechanics work.

If you have a better idea about implementation, then I'm all ears.

Thanks!

Was it helpful?

Solution

It is hard to identify a general problem within your example that requires a program.

Also, when you ask about a Stata program, a Stata programmer tends to imagine that you expect to write program and that way to define a new command, but it's not at all obvious that you really need to write a new command here.

The example I take to be that regress and test could be run repeatedly for different variables.

But some details are obscure. What is Y? Or is it just a way of indicating "Yes"? If you were to run this interactively, the use of local macros would be futile, as you would just be putting a name into a local macro and taking it out again.

If you do write a program, then you need to document it with a help file to explain what it does, or minimally otherwise. For what purpose? So, that a user (you or someone else) can repeat two commands with different details? The gain there is not clear.

As far I understand your problem, the main need is not a program at all, but

  1. To put repeated commands in a do-file and allow that do-file to take arguments. That's a much underestimated possibility. See the [U] manual, 16.4

  2. To learn about looping over variables with a foreach loop.

Note: "local variables" is not standard Stata terminology; they would always be called "local macros". In Stata a variable is a column in the dataset.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top