Quantcast
Channel: Statalist
Viewing all 72904 articles
Browse latest View live

Help to work with matrix in STATA 12

$
0
0


I'm calculating some indexes in the STATA 12 and I'm putting together the schedule so that you can run without error, but in one of those steps I ran into the following error:
matrix operators that return matrices not allowed in this context
r (509);

The commands I'm using were:
gen KK1 = J1 * Z

I'm trying to generate a variable KK1, from the multiplication of another variable J1 and an matrix Z

To generate J1 I used:
gen J1=(1/5564)*QLa
list J1


What am I doing wrong?
Can someone help me?



Unbalanced Panel Data Newbie

$
0
0
Hi all,

I am looking for some help I have an unbalanced panel data set with companies, years, and various ratios. Firstly, I plan to do simple regressions (1 variable regressions), then I will group by country and industry and perform the same simple regressions. After all this, I will do multi-variable regressions.

I was looking for some advice on the unbalanced panel data set. Can I just run a normal linear regression for the 1 variable regressions (regress dependent independent) or do I need to do xtreg dependent independent, (fe or re)? If I run the dependent and all variables together, I get significant p-value with the Hausman Test.

I'm horrible at statistics as well so any advice would be very appreciated. Also, I have trouble what steps to follow for regressions like what I need to run (autocorrelation, heteroskedicity, unit root tests etc).

Thank you so much!

Local macro to import multiple Excel files

$
0
0
I am trying to compile data from a series of Excel workbooks and worksheets, while I have something that works it is rather inefficient coding. I have got company data from 30 companies in Excel format, and these Excel workbooks are in (relatively) consistent structure. The approach I've taken is to simply list each company every time I need to use that foreach loop. For example:
:
 
foreach company in "Company Alpha" "Company Beta" "Company Gamma"  {
  import excel "`company'", sheet("sheetname") clear
  *code applicable to each company
  }
However rather than listing all 30 company names every time, I thought I could apply a local macro, but regardless of how I structure the local macro I cannot seem to make it work.
:
local names `" "Company Alpha" "Company Beta" "Company Gamma" "'
foreach company in `names' {
   import excel "`company'", sheet("sheetname") clear
  *code applicable to each company
  }
This does nothing. I tried adding extra " " in the loop, but get an r(100) using error. Any advice on what I am doing wrong, or if it can be done. Any assistance would be much appreciated

PS - I did consider using a local files macro, and had it working to an extent, but because I also use the company loop names to define variables and save data file makes this method not ideal as it loops the full file name rather than the company name
:
local files : dir "C:\Users\MichaelW\Desktop\Stata working drive" files "*.xlsx"
foreach company in `files' {
 *code applicable to each company
  generate company="`company'"
  generate year="`year'"  
  save "C:\Users\MichaelW\Desktop\Stata working drive" files\_`company'.dta", replace
}

Predictive Probability Plot

$
0
0
I am running an ordinal logit model with an interaction term (
:
ologit DGoodIdea9B i.Frame1#i.SatisfactionYES i.Gender, or robust
). I was advised to draw a predictive probability plot which stimulates different levels of dependent variable.

I need help on how to do this please? I was wondering where this is the same as the marginsplot I have been reading about, however I am unsure what to type into stata especially as I am using an interaction variable. Thank you!

How to interpret Country Dummies

$
0
0
Array Hello
I'm having a slight problem with understanding how to interpret result of my regression, i have inserted a picture below. i am working with panel data (10 countries, 11 years), i am investigating the impact of labour market institutions on Unemployment rate. some papers i ahve read introduce country specific effects but do not interpret.

** I have included country dummies by this command xi: reg $ylist $xlist3 i.country, robust
**Also will time specific effect involve me creating dummie variables as well? Thank you

Lamie

Trouble with -reghdfe- or -ivreg2-: "center not found - struct ms_vcvorthog contains no such member"

$
0
0
Hi all,

I have been working on a project for a few months that involves running some standard 2SLS regressions. I have a high-dimensional fixed effect that I want to control for, so I have been running (in Stata 13):

reghdfe outcome covar (endog=iv), a(fe)

This had been working fine for months, but today when I reran my code, I got the following error:

center not found -- struct ms_vcvorthog contains no such member
(798 lines skipped)

(error occurred while loading ivreg2.ado)

Like I said, this is the same code I was running without problem before, and if I try to run -reghdfe- for a simple regression with auto.dta, I get the same problem. So it doesn't seem to be an issue with the code, but rather it is like the command changed somehow.

When I looked into the documentation of -ivreg2.ado- it says that the data must be a panel, which mine is not. So while this could explain why it is not working now, it does not explain why it worked previously. Are other people finding -reghdfe- is not working on cross-sectional data?

If anyone has a suggestion for how I could fix this - or a different command that would allow me to run 2SLS with a high-dimensional fixed effect, I would really appreciate it.

Josh

Changes in Stata V14 commands compared to V13?

$
0
0
We were using this command in Stata 13 with no problems:

destring count, ignore(,) replace

But we got Stata 14 installed this morning and got this error when we ran the same command on the same dataset:
ignore string must be enclosed with quotes to ignore commas or use options
r(198);

Anyone knows why is that?
Thank you!

Exporting results to Latex after running the Synth command

$
0
0
Hello,

I am running the synthetic control method. And I am using the following command to generate the results for this method.

:
synth  inflation gdpgrowth(1993(1)1998) inflation(1986) inflation(1987) inflation(1988) inflation(1989) inflation(1990) inflation(1991) inflation(1992) inflation(1990) inflation(1991) inflation(1992) inflation(1993) inflation(1994) inflation(1995) inflation(1996) inflation(1997) inflation(1998), trunit(8) trperiod(1999) nested fig
It generates three sets of results, of which one of these is the following:
Array
I would like to export the results of this table which is the second result (out of three) from this command. Would you be able to tell me which command I should use instead of outreg/outreg 2 to export this result.

This method has been used from Abadie et al. (2010) [Available here: http://web.stanford.edu/~jhain/Paper/ccs.pdf]. I have downloaded the synth package for stata, to run this command.

Thank you,
Mridula

stata python plugin compiling: unresolved external symbol __imp__

$
0
0
I tried to compile the python_plugin for stata on a Windows 64 bit machine with python33.lib and Visual Studio Express 2012 (and 2008)
I tried the instructions in
http://fmwww.bc.edu/RePEc/bocode/p/python_plugin.pdf
and tried Release for Win32 and for x64.

Bu i always get 37 Error messages like
Error 1 error LNK2001: unresolved external symbol __imp__PyExc_SystemExit C:\Users\MaxBohnet\Documents\Visual Studio 2008\Projects\stata_python\stata_python\python_plu gin.obj stata_python
Error 2 error LNK2001: unresolved external symbol __imp__PyFloat_FromDouble C:\Users\MaxBohnet\Documents\Visual Studio 2008\Projects\stata_python\stata_python\python_plu gin.obj stata_python
etc.

I found explanations in other forums like:
The __imp__ prefix appears whenever you are linking to a DLL. It does not appear when linking to statically linked libraries. Most likely the code is generated to be linked against a DLL import lib, but you have linked it with a static lib instead.

Bit i am not an expert in Compiling, linking etc. and have no idea what the difference between a static and dynamically linked library is.
So does anybody has an idea how to fix that?

Max

Levpet r(2000)

$
0
0
Hello,

I am using the levpet command on a subsample of my observations (specific sector and year). Here is the code I am executing:

levpet ln_real_VA if NACESHORT==10 & year==2005, free(ln_L) proxy(ln_real_M) capital(ln_real_K) reps(20) level(99)

Unfortunately, Stata keeps sending me back this error message:

"no observations
r(2000);"

The error remains even if I change year or sector.
If I instead use revenues I get a different, yet very similar message.


. levpet ln_real_T if NACESHORT==10 & year==2005, free(ln_L) proxy(ln_real_M) capital(ln_real_
> K) reps(20) level(99) revenue
no observations
error #2000 occurred in program nllp_bs_gmm
r(196);

I am fairly sure there are observation for the subsample since:

count if !missing( ln_real_K, ln_real_M, ln_real_T, ln_real_VA, ln_L) & NACESHORT==10 & year
> ==2005
1167

Where I am getting this wrong?

Thank you for your help,

Luca

How to use IF condition before running a inner loop of FORV

$
0
0
I am struggling with imposing if condition on a inner loop. Consider the following example where a user can input five dependent variables with names S1 S2 S3 S4 S5 or S1H1 S1H2 S1H3 S1H4 S1H5,
:
    local LHS : word 1 of `varlist'
    local S = substr("`LHS'",1,1)
    local H = substr("`LHS'",3,1)
    local NF: word count `varlist'


forv s=1/`NF'{
  *IF condition is required here
      forv h=1/`NF'{
            reg `S'`s'`H'`h' `flist'
      }
}
let say that the user inputs the first series of dependent variables i.e. S1 S2 S3 S4 S5, then I just need the higher loop i.e.
:
 forv s=1/`NF'{
However, if the user inputs the second series i.e., S1H1 S1H2 S1H3 S1H4 S1H5, then I need both the outer and inner loops. i.e.
:
forv s=1/`NF'{
      forv h=1/`NF'{
            reg `S'`s'`H'`h' `flist'
      }
}

-matchit- command to match two datasets based on similar text patterns

$
0
0
Hi,

I have two datasets each containing data on certain firms. I would like to merge the two datasets using the only available option: the name of the firms in the two datasets. Unfortunately, the spellings of firm names are different across the two datasets. Therefor, I looked for a command in Stata that can match the string variables.

I found the command -matchit- and tried it with its several options. But, it under-performs to the extent that it cannot match even the most obvious cases (and sometimes it does the matching correctly). I am not sure if I am making using the command correctly, because the names that I have are not terribly difficult to match.

The first dataset has has two variables: idfocal (codes idntifying a firm), focal (string variable for the name of a firm)
The second dataset has two variables: idlicensor (codes identifying a firm), licensor (string variable for the name of firm)
:
. matchit idfocal focal using licensor.dta, idusing(idlicensor) txtusing(licensor)
The above command is the simplest form of the command (2-gram parsing):

Array

This is strange because the score of the first matching is 0.577 while the score of the last matching (a correct matching) is 0.538. Also, many cases that have to be matched are left out.For example, the name "GENENTECH INC" in the variable "focal" is not matched with the name "Genentech" in the "licensor" variable!


I tried more complex forms of the command and the matching improved (Genentech is now matched) though it was still far from ideal:

:
matchit idfocal focal using licensor_temp.dta, idusing(idlicensor) txtusing(licensor) similmethod(token_soundex) weights(root)  score(minsimple)override
Array


Am I doing something wrong? What other Stata commands are available?

Thanks,
Navid

Testing

$
0
0
\begin{equation}
y_{it} = x_{it}'\beta_1 + y_{i(t-1)}\beta_2 + \alpha_i + \varepsilon_{it}
\end{equation}

As in the conventional linear panel data model the time-invariant unobserved component is related to the regressors but the strategy of taking first differences does not work because of an endogeneity problem. In particular:

\begin{eqnarray}
\Delta y_{it} = \Delta x_{it}'\beta_1 + \Delta y_{i(t-1)} + \Delta \varepsilon_{it}
\end{eqnarray}

Plot logistic regression for categorical data / difference between LOWESS and logit

$
0
0
I am trying to predict the probability for my regression model there are some issues. I tried the command which I learned in class but does not give me a single line but lots of them.
My dependend variable is categorical and can take values for 1, 2 and 3 and I guess it's because of that but I don't know what code to use.

I tried

logit Intention indexn1_
predict p
graph twoway line p Intention , ytitle(Propability)
xlabel(0(10)100) ylabel(0(0.2)1) sort


How do I plot the probability for categorical dependent variables?


Or - is there a crucial difference between LOWESS and the predict c and plot it command? I know that LOWESS gives me a local regression, not a logistic one but honestly, I just want to show the relation between the two variables and if LOWESS gives a very similar result to logit and then predict p, I could ommit the latter.



Thank you in advance.

highest nth observation

$
0
0
Hi,

For example, let's say that I have the following data:

year weight
1990 0.1
1990 0.5
1990 0.01
1990 0.02
1990 0.01 -------->
1991 0.1
1991 0.5
1991 0.01
1991 0.02

and I want to keep the highest three observations in the group.

year weight
1990 0.1
1990 0.5
1990 0.02
1991 0.1
1991 0.5
1991 0.02

Thanks!
Nazlı

Mata function by group

$
0
0
I calculate a real-valued scalar by using the following program:

/* myproc.ado */
capture program drop myproc
program define myproc
mata: myindexfunc()
gen myindex=MYINDEX
end

mata:
void myindexfunc() {
xvar = st_data(.,"xvar")
yvar = st_data(.,"yvar")
lat = st_data(.,"lat")
lon = st_data(.,"lon")
n = length(xvar)
d = J(n, n, .)
for (i=1;i<=n;i++) {
for (j=1;j<=n;j++) {
d[i,j]=exp(-sqrt((lon[i]-lon[j])^2+(lat[i]-lat[j])^2))
}
}
myindex = cross(cross(xvar,d)',yvar)/sum(xvar)/sum(yvar)
st_numscalar("MYINDEX",myindex)
}
end

The program above creates the "myindex" variable that contains a single value of "MYINDEX". The problem here is that my data file has a group variable (say, "group") along with xvar, yvar, lat, lon. My goal is to apply the mata function "myindexfunc()" by group. How do I have to modify the program to do the operation by group?

Error r(430); after svy logistic

$
0
0
After executing this code I'm getting the following:

svy linearized : logistic dv IBM demo if r1d ==1 & r1femage80

convergence not achieved
convergence not achieved
an error occurred when svy executed logistic
r(430);

I have tried for this other variables: r1femage81 r1malege80 r1malege81 replacing r1femage80 and it run perfectly!!

this is the general code for each variable:

generate r1femage80 = r1dg==2 & r1ageme80 ==1
generate r1femage81 = r1dg==2 & r1agema80 ==1
generate r1malege80 = r1dg==1 & r1ageme80 ==1
generate r1malege81 = r1dg==1 & r1agema80 ==1

what might be wrong?

thank you all for your input!

p-value of F-statistic for each group

$
0
0
Hi, In my data set I have 470 companies and I got group wise estimations and their p values using parmby. I'm wondering whether there is any way to get the p-value of the F-statistic for each regression, group wise. Thank you

Dialog Programming: Collapsed Treeview

$
0
0
Dear all,

presently I am working on a dialog that should contain a relatively long and complex tree in a TREEVIEW component. I would like to have this tree start in collapsed mode so that the first level of nodes is completely visible. Is there any way to achieve this directly? The help file does not mention anything, I think.

Best,
Felix

gmm command: error message &quot;could not evaluate equation 1&quot;

$
0
0
Please ignore the post, the issue has been resolved. Apologies
Viewing all 72904 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>