Stata Outreg2: file handle __00000G not found - stata

I'm running a long list of regressions in Stata. Results are exported using outreg2. At random points in time, the execution stops at some outreg2 with the error file handle __00000G not found. When I rerun the whole exercise it works after some tries. Do you have any idea what could be the reason?
My code looks as follows where further regressions of the same type follow.
xtreg l_GDP_capita i.year date_intens, fe r
outreg2 using year_DG_FE_gdp, excel append label addtext(DG FE, YES, YEAR FEs, YES) drop(i.year) ctitle(log GDP per capita, AP) replace
xtreg l_GDP_capita i.year date_intens if any_lez==1, fe r
outreg2 using year_DG_FE_gdp, excel append label addtext(DG FE, YES, YEAR FEs, YES) drop(i.year) ctitle(log GDP per capita, LEZ)

Two thoughts:
(1) your file name needs to be in quotations, so outreg2 using "year_DG_FE_gdp", [blah] instead of outreg2 using year_DG_FE_gdp, [blah].
(2) In case you haven't done so, you need to set a directory. cd "whatever filepath you want to save to" (or a global directory if you want to get fancy). You may have done this earlier in your code (I usually do it at the top of a .do file), but since you've only posted the snippet here I can't tell. Forgetting it is one of the classic problems people tend to have with outreg.

Not 100% sure, but I am having the same problem and I think this may arise when outreg2 is writing to a directory that is being synced (e.g. Dropbox, Google Drive). I believe the conflict may come from a permissions conflict where Stata is trying to change the file as the sync software is uploading the change. If you can pause the syncing of the directory while running the Stata commands, this seemed to help me.

Related

pre_limit_mult in synth_runner package does not work well

This might be similar to this question (pre_limit_mult in synth_runner package stata does not work), However, I ask this because I could not find any useful tips from the link.
I am trying to use the pre_limit_mult(real) option to limit the placebo effects in the pool for inference. The ultimate purpose is to test the validity of estimation of the economic impact of the coup in Gambia in 1994.
However, even though I follow the practice as the guidebook explains, the command does not work and present the message like the following.
tsset country_id year
synth rgdpe pop rconna csh_i csh_x rgdpe(1971) rgdpe(1982) rgdpe(1993), trunit(21) trperiod(1994) keep("Gambia_outout") replace fig
local K = 2
synth_runner rgdpe pop rconna csh_i csh_x rgdpe(1971) rgdpe(1982) rgdpe(1993), trunit(21) trperiod(1994) keep("Gambia_outout") replace gen_vars pre_limit_mult(`K')
single_treatment_graphs, trlinediff(-1) raw_gname( rgdpe_raw) effects_gname(rgdpe_effects) effects_ylabels(-1500(750)1500) effects_ymax(2000) effects_ymin(-2000) do_color(bluishgray)
With -, gen_vars- the program needs to be able create the following variables: lead rgdpe_sy nth effect pre_rmspe post_rmspe. Please make sure there are no such varaibles and that the dependent variable [rgdpe] has a short enough name that the generated vars are not too long (usually a max of 32 characters)
I received this message.
With -, gen_vars- the program needs to be able create the following variables: lead rgdpe_synth effect pre_rmspe post_rmspe.
Please make sure there are no such varaibles and that the dependent variable [rgdpe] has a short enough name that the generated vars are not too long (usually a max of 32 characters).
Please download the input data and dofile from the following link (I could not find the way to directly attach the file in stackoverflow).
(https://drive.google.com/drive/folders/1VyP2GN3NfQT6jQ9enbCvE2VTVNxZdPgc?usp=sharing)
Does anyone know how to fix it?

Stata: Esttab of xtreg with time fixed effects

I'm trying to save output from several hundred eststo's storing results of bivariate probability models into one excel file using esttab. It works for xtlogit(both ,re and ,pa), xtprobit (both ,re and ,pa) and for the linear probability model xtreg (both standard and ,fe. However, when I use xtreg y x i.year, fe I get the error message too many base levels specified. Google doesn't help me much.
I've been trying for an hour to create a reproducible example but the stata datasets all work fine. It does not seem to be due to the number of years or the fact that different specifications have data for different years. Still, the normal xtreg, fe' works, the problem only appears with time dummies. The weirdest thing is that it works for all subsets of my variables but not for the whole list (again just the time fixed effects specifications).
Does anyone have an idea how to proceed? Using drop(*.year) works whenever the problem does not arise (so in specifications where it works, I get outputs without the year dummies) but does not prevent the too many base levels specified error; ,nobaselevels has no apparent effect as well. Is there a way to remove the time fixed effects from eststo before I pass those on to esttab? Any workaround would be appreciated as well.
The problem you might be facing is that of Stata creating different base levels for the factor variable year, in different regressions.
Try fixing the factor variable base level beforehand with fvset:
fvset base <some_number> year
Check help fvset and the manual entry for details. Also, read the source given below, which contains more information.
Source: two posts from Statalist; one from Tim Wade and another by Jeff Pitblado.

esttab estimations results do not have e(b) and e(V)

I have been using the estout commands for quite some time now, but am now working on a couple of computers that are not connected to the internet. I have been getting the following error from the esttab command:
current estimation results do not have e(b) and e(V)
To test this with a simpler example, I tried to replicate the example here: http://repec.org/bocode/e/estout/estpost.html#estpost101
I created a sample dataset as below:
price mpg rep78 foreign
1 3 1 1
2 3 1 1
3 3 1 2
4 3 2 3
5 3 2 5
6 3 2 8
7 3 3 13
8 3 3 21
9 3 3 34
And then ran the following commands as per the example:
estpost summarize price mpg rep78 foreign, listwise
esttab, cells("mean sd min max") nomtitle nonumber
I got the expected output with the estpost command, but got the aforementioned error when running esttab. I have uninstalled and reinstalled this package several times, using both a version downloaded onto another computer using ssc install and a version downloaded from http://repec.org/bocode/e/estout/installation.html. I feel that I must be missing something obvious...any help would be appreciated.
EDIT: I just checked with a colleague of mine, and it seems they have been inexplicably getting the same error recently.
This works for me. I suspect faulty installation. Despite your best efforts, you may have previously installed versions of some or all of the programs in estout on your system.
In Stata, you need to check what Stata is seeing by typing commands such as
. which esttab, all
in every directory in which you work. If necessary, repeat for all the other command files in the package as named by ssc desc estout. You should be seeing one (and only one) version of each command, dates mostly in 2009 (eststo in 2008).
A wilder hypothesis is that estout has been broken by recent changes in Stata. This seems unlikely to me, but check the above first.
(UPDATE) OP reply reveals a nightmare scenario: old versions have been found that are difficult to remove. What to do?
Look at the adopath command. In the first instance, just type adopath. Stata wants to install estout stuff in an e off whatever it labels PLUS. (If you are in the US, you probably want to say "off of".)
One possibility is that you use adopath to reset PLUS to somewhere you have write access, preferably somewhere dedicated to programs alone. That's got implications for programs already in PLUS, which are now longer visible, so you need to add whatever is now PLUS as an extra place to look. The help for adopath explains how to do this.
Another possibility is that Stata always looks in the current directory or folder for a user-written program before it looks in PLUS (unless you mess with that order, which I advise against). So, so long as programs you want are in the current directory, that should work. However, this would usually be considered poor style. Worse, as you change the working directory, you need to copy programs to that directory.
You may need to approach the administrators to delete the old stuff. It is hard to work with user-written programs for Stata if you don't have the right privileges.

How to post Stata program via Dropbox or private website?

Here is a sample program .do file, sampleprog.do:
program sampleprog
egen newVar = group (`1' `2')
end
How can I post it on my website (or dropbox), so that other people could install it to their Stata like this?
net from http://www.mywebsite.com/sampleprog.do
*** or may be like like this:
ssc install ...
I read the documentation about stata.toc...but I did not quite get it. What files should I upload and should it be one folder or what?
(PS: I definitely can simply email the .do file but this is not an option in my case.)
Here is a full explanation of how to share program or data files with others using your own website. I tried using Dropbox, but Stata 12 appears to have issues with https, which is the protocol for all Dropbox public links. If you want to use Dropbox, I recommend creating a shared folder that will sync on your collaborators' machines. The rest of this answer assumes you have a website serving pages over http or are using Stata 13, which supports https.
If this is a one-time thing, you can skip the rest of this answer by putting the file on your website and telling your collaborator to type:
. copy http://your-site.com/ado/program.ado program.ado
That will copy the ado file at the specified url into the user's current directory. If you want to provide information about your files, plan on sharing with multiple people and need to maintain/document a set files, read on!
Step 1 Create a folder on your website to hold the programs. I will call mine ado/
Step 2 Add the program files, help files, and data files you want to share. For this example, I have created a simple ado file called unique.ado with the following contents:
********************************************** unique.ado
capture program drop unique
program define unique
*! Count and number observations within group defined by varlist
* Example: unique person_id, obs(prow) tobs(pcount) sortby(time)
* to count and number rows by a variable called person_id
syntax varlist, obs(name) tobs(name) [sortby(varlist)]
bys `varlist' (`sortby') : gen long `obs' = _n
bys `varlist' (`sortby') : gen long `tobs' = _N
la var `obs' "Number of this row within `varlist' group."
la var `tobs' "Total number of rows with identical `varlist' values."
end
Step 3 Create a file called stata.toc to describe the files you wish to share. Here is mine:
********************************************** stata.toc
v 3
d Program to count observations by group
p unique [The unique.ado program for counting observations by group]
These files can be complicated. There are many features I won't cover here, but you can read this documentation to learn more.
Step 4 Create a package file for each of the packages defined by the lines in stata.toc that start with the letter p. Here is my package file for the unique package defined above:
********************************************** unique.pkg
v 3
d unique
d Program to count observations by group
d Distribution-Date: 28 June 2012
f unique.ado
Your directory now looks like this:
ado/
stata.toc
unique.ado
unique.pkg
Step 5 Use the site! Here are the commands to enter.
. net from http://example.com/ado/
. net describe unique
. net install unique
Here is what you'll see after entering the first command:
-----------------------------------------------------------------------------------
http://www.example.com/ado/
Program to count observations by group
-----------------------------------------------------------------------------------
PACKAGES you could -net describe-:
unique [The unique.ado program for counting observations by group]
-----------------------------------------------------------------------------------
The second command will tell you more about the package net describe unique:
---------------------------------------------------------------------------------------
package unique from http://www.example.com/ado
---------------------------------------------------------------------------------------
TITLE
unique
DESCRIPTION/AUTHOR(S)
Program to count observations by group
Distribution-Date: 28 June 2012
INSTALLATION FILES (type net install unique)
unique.ado
---------------------------------------------------------------------------------------
The third command will install the package net install unique:
checking unique consistency and verifying not already installed...
installing into /Users/cpoliquin/Library/Application Support/Stata/ado/plus/...
installation complete.
EDIT
See Nick's comments in the answer below. I intended this example to be simple and I don't expect other people to use this program. If you plan on submitting things to Stata Journal or SSC then his comments certainly apply! I hope this answer can serve as a decent tutorial for those confused by the official documentation.
This will be too long for a comment, so it is going to be an extra answer.
Your example uses the program name unique. If you search unique, all (or in Stata 13, search unique) you will find that a user-written program with the same name has been installed on SSC since 1998. This will create a clash of names for your users if (and only if) they attempt to use your program and also that earlier program. The more general advice is to search to see if a program name is already in use to try to avoid these problems.
Specifically, although you may just be using your unique as an arbitrary example, note that it contains bugs. An int doesn't contain enough bits to hold observation numbers exactly for large datasets. Also, as a matter of style, unique can change the sort order of your data, which is widely considered to be poor data management style.
Your example concerns dissemination of a program file without an accompanying help file. Suffice it to say that the SSC site would never accept such a program and the Stata Journal would not even review a paper based on such a submission before a help file was written to accompany it. Including explanatory comments with the code may be sufficient for your personal practices, but it falls below general Stata standards.
Stata 13 now supports https. See http://www.stata.com/manuals13/u.pdf, Section 3.6.
In short, I appreciate that you are trying to explain how to do something, but it is already well documented, and explicitly and implicitly some of your recommendations are below community standards.

how to make tables out for Spearman correlation table? [duplicate]

This question already has an answer here:
How to export Spearman correlations
(1 answer)
Closed 3 years ago.
I need to get a Spearman and Pearson correlation table using Stata. Here is what I did to get the results in a table format.
estpost correlate sp_rating srating mrating split split_neg split_ord split_neg_ord tier1_risk tier1_leverage st1 sl mt1 ml adt1 adl dt1 dl offering_amt maturity2 security
enhance timeliness validity disc loan_at cash_dep trading_at real_est intangible other_at sec_sum assets_sold all_residual secinc_ta, matrix quietly
esttab . using "root4.rtf", replace notype unstack compress noobs nogaps nostar
Then, I get this error message:
varlist not allowed
When I used just a few variables, I didn't get the error, but when I put many variables. I don't know how to fix this. Please help me.
I was able to reproduce your error and ran a trace on it. I believe this is a bug at line 946 of estout.ado, perhaps caused by the fact that a very long variable list with RTF tags exceeds the size of the local macro created at that line.
You should send a bug report to Ben Jann (email at the end of help estout). In the meantime, you can try saving to DOC and TXT, both of them might work (you have over 30 variables, I tested both .txt and .doc successfully with something like 20 variables).
Alternately, try the mkcorr command (ssc install mkcorr) to see if it works with your data.
I just had the same problem after I tried a lot of different esttab outputs and had stored a lot in estimates.
So, maybe estimates clear helps if you type it before running your command. At least for me it worked.