Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running Tax-Calculator from Stata #2273

Closed
MaxGhenis opened this issue Mar 25, 2019 · 14 comments
Closed

Running Tax-Calculator from Stata #2273

MaxGhenis opened this issue Mar 25, 2019 · 14 comments
Labels

Comments

@MaxGhenis
Copy link
Contributor

I was speaking to a poverty researcher who works primarily in Stata, and for tax calculation exports the file to CSV, then runs taxcalc via the CLI, then re-imports the result to Stata. Is there a simpler way I can recommend? I don't have Stata to test myself, but given its high usage among policy researchers it might be good to have some instructions like "taxcalc for Stata users."

@feenberg
Copy link
Contributor

feenberg commented Mar 25, 2019 via email

@martinholmer
Copy link
Collaborator

@feenberg, thanks for your helpful suggestion about how to run the Tax-Calculator tc tool from inside Stata.
Here is what you suggested:

outsheet var1...varn using data
! /path/to/taxcalc ...
insheet using results

The command-line tool is called tc and the results file will be some filename ending in .csv whose name will depend on the arguments used to invoke the tc tool. So, just for clarity the Stata command would look like this:

outsheet var1...varn using data
! /path/to/tc ...
insheet using results.csv

@martinholmer
Copy link
Collaborator

@MaxGhenis, Was Dan's suggestion helpful to the poverty researcher you were talking with?

@rHrtly
Copy link

rHrtly commented Mar 28, 2019

Hi @feenberg,

Thanks for your response, and thanks @MaxGhenis for posting after our conversation. Dan, you have helped me before on Taxsim issues, so it's nice to hear from you again.

Sorry I am slow to respond (job market flyout!). So, yes, the shell command Dan suggests is what I usually do, though I think the problem I am having is that I am using an institutional computer and the Anaconda installation did not set up the environment such that I can call tc from outside of the Anaconda prompt. Does that make sense? I can manually interact with the Windows command prompt to establish the environment within the Taxcalc folder and then call tc from there, but I think I would need a script to do something like this from Stata. Probably, the solution is to go back to my admin and set up Anaconda again so that I can run this more easily.

Thanks for the help, I will update when I get it to run successfully.

Regards,
Rob

@feenberg
Copy link
Contributor

feenberg commented Mar 28, 2019 via email

@martinholmer
Copy link
Collaborator

@rHrtly and then @feenberg said:

Sorry I am slow to respond (job market flyout!). So, yes, the shell command
Dan suggests is what I usually do, though I think the problem I am having is
that I am using an institutional computer and the Anaconda installation did
not set up the environment such that I can call tc from outside of the
Anaconda prompt. Does that make sense? I can manually interact with the

Is tc in the executable path? If not, then could modify the path within
the Anaconda environment to include the directory with tc, or much easier
you could specify the full path to the tc executable.

Don't know about how Anaconda works on Windows, but on both Mac
and Linux the tc command is visible everywhere on the computer
without the use of a path.

Or is it that in the Anaconda environment there is a missing library, so
that tc won't link? That can also be addressed, by adding to the load
library path.

@rHrtly, Please report back on your experience as we are handicapped
because none of the Tax-Calculator developers are working on Windows.
So it is impossible to "see" the kinds of problems you're experiencing.

@rHrtly
Copy link

rHrtly commented Mar 28, 2019

Hi @martinholmer and @feenberg,

I have tried using full paths to my input files and the tc executable file. I think a helpful example is, as mentioned, I cannot run tc from the command prompt unless I establish the anaconda environment first.

I followed this sequence based on the contributor guide:

From your command line or terminal, navigate to your local Tax-Calculator directory.
Create a conda environment with all of the necessary packages to execute the source code:
Tax-Calculator$ conda env create
The prior command will create a conda environment called “taxcalc-dev”. If you are working on Windows, use the following from the command line:
Tax-Calculator$ activate taxcalc-dev
Then I changed directories and ran a simple tc command, and it worked.
Tax-Calculator$ cd taxcalc
tc ...

This is the only way I've gotten tc to work without calling it from the Anaconda prompt. So, again, my guess is that I need an admin to change something about my Anaconda installation in order for the proper library paths to be found?

@martinholmer
Copy link
Collaborator

@rHrtly said in issue #2273:

I have tried using full paths to my input files and the tc executable file. I think a helpful example is, as mentioned, I cannot run tc from the command prompt unless I establish the anaconda environment first.
...
So, again, my guess is that I need an admin to change something about my Anaconda installation in order for the proper library paths to be found?

Probably not. My understanding is that Anaconda works fundamentally different on Windows from the way it works on Mac and Linux. It is so cumbersome under Windows, that the first developers of Tax-Calculator (according to what I've heard) had to trade-in their Windows computers for Mac computers in order to be productive in their development work.

@rHrtly
Copy link

rHrtly commented Apr 3, 2019

So, I had some time to revisit this and received some guidance from a friend, and here is the solution we found: apparently all I needed was to add Python/Conda to my path in command prompt, and now I can shell out from Stata easily.

C:\Users\username>SETX PATH "%PATH%;C:\Anaconda3\Scripts;C:\Anaconda3"

Now, in Stata I can use:

shell tc cps3yr.csv ...

where the data file and associated reform or other files are located within the Stata current working directory. Stata runs the shell command, and waits until it is finished, then proceeds with the next command, which is perfect for what I was wanting.

@martinholmer
Copy link
Collaborator

@rHrtly described how to run the Tax-Calculator tc tool from inside Stata on Windows in this comment.

Thanks for sharing the answer to the question posed in issue #2273.

So, it seems you need to add two directories to the Windows path, right?

I don't have any Stata experience, is the shell command a Stata command?

@rHrtly
Copy link

rHrtly commented Apr 3, 2019

I think that's right, @martinholmer.

And in Stata, if you want to invoke an operating system command, you would precede the command with either "shell" as I did, or "!" as @feenberg posted earlier. Here are the detailed options from Stata's help file:

**shell** (synonym:  "!") allows you to send commands to your operating system or to enter your operating
system for interactive use.  Stata will wait for the shell to close or the operating_system_command to
complete before continuing.

**winexec** allows you to start other programs (such as browsers) from Stata's command line.  Stata will
continue without waiting for the program to complete.

**xshell** (Stata for Mac and Unix(GUI) only) brings up an xterm in which the command is to be executed.

@martinholmer
Copy link
Collaborator

@rHrtly, Thanks for answering my questions.
I'll see if there's a way to work your insights into the tc documentation.

@rHrtly
Copy link

rHrtly commented Apr 3, 2019

Thanks @martinholmer! and thank you @MaxGhenis for posting the question here.

@martinholmer
Copy link
Collaborator

Issue #2273 has been resolved by pull request #2286.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants