import data via odbc
by RENIER Mélanie
Dear All,
I have one problem when trying to import data via odbc.
It connect to the server but does not achieve to load the data.
I have the following message error:
? open dsn=inf1 --odbc
Connected to ODBC data source 'inf1'
? data x y query="select code,denomination from usig.co_etciv" --odbc
Error executing script: halting
> data x y query="select code,denomination from usig.co_etciv" -odbc
Do you maybe know where does the problem come from or where I can have more details?
Thanks in advance,
Kind Regards,
Mélanie Renier
13 years, 11 months
Re: [Gretl-users] on freq command II
by Allin Cottrell
On Mon, 31 Jan 2011, Leon Unger wrote:
> I guess I found a small bug:
> Namely, when performing the freq command via script the graph isn't shown.
It's not a bug, though maybe it's a mis-feature. The help for
"freq" states:
"In interactive mode a graph of the distribution is displayed by
default. The --quiet flag can be used to suppress this."
Allin Cottrell
13 years, 11 months
on delete command
by Leon Unger
Hi there,
that is my short script:
scalar smpl_size=25
nulldata smpl_size
scalar n = $nobs
scalar nr=100
series betas = NA
loop i=1..nr --quiet
series x_$i=randgen(u,0,100)
series v_$i=randgen(n,0,1)
series y_$i=x_$i+v_$i
ols y_$i x_$i --quiet
betas[$i]=$coeff
endloop
*delete x_* y_* v_**
series betas_norm=sqrt(n)*(betas-1)
And deleting is not performed, "because the variables are in use".
Do you know a solution?
Best
Pindar
13 years, 11 months
Re: [Gretl-users] on delete command
by Allin Cottrell
On Mon, 31 Jan 2011, Leon Unger wrote:
> that is my short script:
>
> scalar smpl_size=25
> nulldata smpl_size
> scalar n = $nobs
> scalar nr=100
> series betas = NA
>
> loop i=1..nr --quiet
> series x_$i=randgen(u,0,100)
> series v_$i=randgen(n,0,1)
> series y_$i=x_$i+v_$i
> ols y_$i x_$i --quiet
> betas[$i]=$coeff
> endloop
> *delete x_* y_* v_**
> series betas_norm=sqrt(n)*(betas-1)
>
> And deleting is not performed, "because the variables are in use".
> Do you know a solution?
The series are "in use" in the sense that they are referenced by
the last estimated model. You can displace that "last model" by
running a dummy regression before issuing the delete command:
ols 0 0 --quiet
delete x_* y_* v_*
Allin Cottrell
13 years, 11 months
on freq command II
by Leon Unger
Hi there,
I guess I found a small bug:
Namely, when performing the freq command via script the graph isn't shown.
Cheers
Pindar
13 years, 11 months
Re: [Gretl-users] Nonlinear switching regression vs Loop constructs
by Allin Cottrell
On Fri, 28 Jan 2011, Allin Cottrell wrote:
> Anyway, in case it's of interest, I'm appending below a re-write
> of the grid-search variant...
>
> In this version I've also rescaled the data to make the results
> comparable with Jack's NLS variant.
Oof, another mistake, HHI should not be scaled -- or not without
adjusting the mu, sigma ranges.
> <script>
...
> HHI *= 100
If you delete that line in the script I posted last you find that
the (mu, sig) choice makes a tiny difference to the fit, with an
apparent max at (0.3, 0.01). But we're talking about the 4th
decimal place in the R^2.
Allin Cottrell
13 years, 11 months
Re: [Gretl-users] Nonlinear switching regression vs Loop constructs
by Allin Cottrell
On Fri, 28 Jan 2011, GREg Ory wrote:
> I need some tips on estimating panel data using nonlinear switching
> regression technique. AFAIK there are two ways of solving it...
OK, so now you have two attempted solutions, Jack Lucchetti's (via
nls) and mine (via grid-search over mu, sigma). Each has problems:
Jack's does not constrain mu and sigma in the range that you say
is acceptable, and mine has a couple of errors: missing the factor
of pi/sqrt(3) in building the "logist" series, and failing to
notice (as per the PDF you attached) that the coefficient on the
"logist" term is constrained to equal 1 (without which constraint,
I suppose, the thing is not identified).
Our candidate solutions also differ in whether they build in fixed
effects (mine does, by using the "panel" command) or not (Jack's).
I'm not sure which is appropriate.
Anyway, in case it's of interest, I'm appending below a re-write
of the grid-search variant that fixes the mistakes noted above. If
you want to remove the fixed effects, just put "ols" instead of
"panel" for the estimation commands.
In this version I've also rescaled the data to make the results
comparable with Jack's NLS variant. And I've added a check: I
noticed that when I ran the script the "optimal" mu and sig were
at the lower limits of their ranges. But, given the way the script
is written, this doesn't necessarily mean these values are
"superior" -- all it means is that were not improved upon by any
other values. So I also try running the panel model with mu and
sig at the upper limits of their ranges -- and I find this makes
no difference to the fit.
That is, it appears that variation in mu and sig, within the
limits you specified, is completely irrelevant to the fit of the
equation.
<script>
open gretl_plant.gdt
scalar R2max = 0
scalar optmu
scalar optsig
scalar nvals = 0
# apply Jack's scaling
Price /=100
HHI *= 100
Domestic_Sales /= 10000
Export_Sales /= 10000
Total_import /= 10000
loop for (mu=0.28; mu<0.501; mu+=.01) --quiet
loop for (sig=0.01; sig<0.201; sig+=.01) --quiet
series logist = 1/(1+exp(1.8138*(mu-HHI)/sig))
series y = Price - logist
panel y const Cost Domestic_Sales Export_Sales \
Soda PCFT Total_import --quiet
r2 = $rsq
if r2 > R2max
optmu = mu
optsig = sig
R2max = r2
endif
nvals++
endloop
endloop
printf "Number of points checked = %d\n", nvals
printf "R^2 is maximized at %.4f for mu = %g, sig = %g\n",
R2max, optmu, optsig
series logist = 1/(1+exp(1.8138*(optmu-HHI)/optsig))
series y = Price - logist
panel y const Cost Domestic_Sales Export_Sales \
Soda PCFT Total_import
# but also try setting (mu, sig) to max acceptable values
optmu = 0.5
optsig = 0.2
series logist = 1/(1+exp(1.8138*(optmu-HHI)/optsig))
series y = Price - logist
panel y const Cost Domestic_Sales Export_Sales \
Soda PCFT Total_import
</script>
Allin Cottrell
13 years, 11 months
Re: [Gretl-users] Nonlinear switching regression vs Loop constructs
by Allin Cottrell
On Fri, 28 Jan 2011, GREg Ory wrote:
> I need some tips on estimating panel data using nonlinear switching
> regression technique. AFAIK there are two ways of solving it.
>
> The model I estimate is the following:
> panel Price const Cost logist Domestic_Sales Export_Sales Soda PCFT Total_import
>
> Logistic function is given as logist = 1/(1+exp(1,81*(mu-HHI)/sig)).
If I understand the problem correctly you should probably be able
to do this via nls, though you'd have to create the fixed-effects
dummies and enter them yourself ("genr unitdum"). However, if you
take the grid-search approach for mu and sigma then something like
the following should work:
<script>
open gretl_plant.gdt
scalar R2max = 0
scalar optmu
scalar optsig
scalar nvals = 0
loop for (mu=0.28; mu<0.501; mu+=.01) --quiet
loop for (sig=0.01; sig<0.201; sig+=.01) --quiet
series logist = 1/(1+exp((mu-HHI)/sig))
panel Price const Cost logist Domestic_Sales Export_Sales \
Soda PCFT Total_import --quiet
r2 = $rsq
if r2 > R2max
optmu = mu
optsig = sig
R2max = r2
endif
nvals++
endloop
endloop
printf "Number of points checked = %d\n", nvals
printf "R^2 is maximized at %.4f for mu = %g, sig = %g\n",
R2max, optmu, optsig
series logist = 1/(1+exp((optmu-HHI)/optsig))
panel Price const Cost logist Domestic_Sales Export_Sales \
Soda PCFT Total_import
</script>
Allin Cottrell
13 years, 11 months
Nonlinear switching regression vs Loop constructs
by GREg Ory
Dear Gretl community,
I need some tips on estimating panel data using nonlinear switching
regression technique. AFAIK there are two ways of solving it.
The model I estimate is the following:
panel Price const Cost logist Domestic_Sales Export_Sales Soda PCFT Total_import
Logistic function is given as logist = 1/(1+exp(1,81*(mu-HHI)/sig)).
Height of the logistic function is between 0.025 and 0.975.
Mu = mean(height)
Sig = var(height)
The datafile is attached in case anybody wants to help tackle the
model directly. The theoretic foundation for this analysis is also
attached in the PDF article. I tried to use simultaneous equations to
estimate this model properly but to no avail.
Second best option is to use loop constructs to model all possible
parameter values in the given range then to choose the model with the
highest $rsq. Mu should be in the range of 0.28 to 0.501 and sig
between 0.01 and 0.201. However I have a problem with implementing a
proper loop. Here is an example
nulldata 100
set seed 2478
HHI =randgen(u,0.21,0.27)
P = randgen(u,100,300)
# open two loops for estimated params
loop for (mu=0.28; mu<0.501; mu+=.01)
loop for (sig=0.01; sig<0.201; sig+=.01)
# construct the dependent variables
genr height = randgen(u,0.025,0.975)
genr mu = mean(height)
genr sig = var(height)
genr logist = 1/(1+exp((mu-HHI)/sig))
# run OLS regression as an example
ols P const logist
# grab the coefficient estimates and R-squared
genr b1 = $coeff(const)
genr b2 = $coeff(logist)
genr r2 = $rsq
print a b r2
store coeffs.gdt a b r2
endloop
endloop
My problem is twofold: 1st loop worls perfectly but 2nd loop doesn’t
work. R2 is not saved to a coeffs.gdt file. Any help to estimate the
model using those or other methods is appreciated.
Best Regards,
Gregory
13 years, 11 months
Re: [Gretl-users] Nonlinear switching regression vs Loop constructs
by Allin Cottrell
On Fri, 28 Jan 2011, GREg Ory wrote:
> I need some tips on estimating panel data using nonlinear switching
> regression technique. AFAIK there are two ways of solving it.
>
> The model I estimate is the following:
> panel Price const Cost logist Domestic_Sales Export_Sales Soda PCFT Total_import
>
> Logistic function is given as logist = 1/(1+exp(1,81*(mu-HHI)/sig)).
>
> Height of the logistic function is between 0.025 and 0.975.
> Mu = mean(height)
> Sig = var(height)
>
> The datafile is attached in case anybody wants to help tackle the
> model directly. The theoretic foundation for this analysis is also
> attached in the PDF article. I tried to use simultaneous equations to
> estimate this model properly but to no avail.
>
> Second best option is to use loop constructs to model all possible
> parameter values in the given range then to choose the model with the
> highest $rsq. Mu should be in the range of 0.28 to 0.501 and sig
> between 0.01 and 0.201. However I have a problem with implementing a
> proper loop. Here is an example
>
> nulldata 100
> set seed 2478
> HHI =randgen(u,0.21,0.27)
> P = randgen(u,100,300)
> # open two loops for estimated params
> loop for (mu=0.28; mu<0.501; mu+=.01)
> loop for (sig=0.01; sig<0.201; sig+=.01)
> # construct the dependent variables
> genr height = randgen(u,0.025,0.975)
> genr mu = mean(height)
> genr sig = var(height)
> genr logist = 1/(1+exp((mu-HHI)/sig))
> # run OLS regression as an example
> ols P const logist
> # grab the coefficient estimates and R-squared
> genr b1 = $coeff(const)
> genr b2 = $coeff(logist)
> genr r2 = $rsq
> print a b r2
> store coeffs.gdt a b r2
> endloop
> endloop
Comments:
* In the inner loop you define b1 and b2, but you attempt to print
and save a and b (both undefined). Easily fixed, of course.
* The saving of scalar values to file via "store" is supported
only for "progressive" loops, so you'd have to append the
--progressive flag to the inner loop command to get this
effect.
* However, that would not do what you want: since the "store"
occurs in the inner loop, coeffs.gdt would be over-written on
each iteration of the outer loop and at the end would contain
only the values for mu = 0.5.
* Your loops may well be infinite (and in case are not doing what
you want) because of the way you use mu and sig as loop control
variables but also reset their values within the inner loop:
> genr mu = mean(height)
> genr sig = var(height)
You need to use different names for these inner variables.
* You don't actually _read_ mu or sig, as set by the loop control
"for" expressions, anywhere inside the loop, so I'm left without
much idea of what the loop is actually trying to do.
Allin Cottrell
13 years, 11 months