Clock function in Stata 9 - function

I am using an old version of Stata, Stata 9, and I am trying to use the clock() function to convert some dates.
gen double Sgytime = clock (surgerystartdatetime, "dmyhm").
Stata says clock not found. Help please.

The function clock() was introduced in Stata 10. That is documented for all to see at http://www.stata.com/help.cgi?whatsnew9to10
Your options are to find a version of Stata that is 10 or higher, to write your own commands (not functions) to handle date-time data, or to use the user-written command ntimeofday published in the Stata Journal. search ntimeofday will indicate a download source. Note that the latter command does not work as clock() does, and in general Stata 9 just does not recognise date-time variables as such.
A larger question is that you are evidently getting ideas from material written for later versions of Stata, but the help and manuals for Stata 9 are the only completely reliable guide to what functions are available to you.

I think you may have an extra space between clock and the first parenthesis:
. display %tc clock("5-12-1998 11:15", "MDY hm")
12may1998 11:15:00
. display %tc clock ("5-12-1998 11:15", "MDY hm")
clock not found
I am assuming that in the search for lost time you have already verified that Stata (and not STATA) 9 has the clock function by looking at the documentation.

Related

Octave Change UIControl Position

The following is example code from Matlab. It doesn't run in Octave. The code is:
f = figure;
b = uicontrol(f,'Style','pushbutton');
b.Position = [100 100 50 20];
It is from the online documentation: https://www.mathworks.com/help/matlab/ref/matlab.ui.control.uicontrol-properties.html
In Octave, I get: error: scalar cannot be indexed with .
What change must be made to make this run in Octave?
MATLAB introduced the second version of the handle graphics system (HG2) a couple of years ago. Octave still uses the old system.
Every time you see handle.propery, you are dealing with HG2. In the original system, we used get(handle,'property') and set(handle,'property',newvalue). Note that MATLAB will not deprecate this original syntax any time soon, it is perfectly valid to use both forms with the newer versions of MATLAB. Thus, the set and get functions are to be preferred for compatibility reasons.
So you can replace
b.Position = [100 100 50 20];
with
set(b,'Position',[100 100 50 20]);

CUDA tridiagonal solver function (cusparse)

In my CUDA code I am using cusparse<t>gtsv() function (more precisely, cusparseZgtsv and cusparseZgtsvStridedBatch ones).
In the documentaion it is said, that this function solves the equation A*x=alpha *B. My question is - what is alpha? I didn't find it as an input parameter. I have no idea how to specify it. Is it always equals to 1?
I performed some testing (solved some random systems of equations where tridiagonal matrices were always diagonally dominant and checked my solution using direct matrix by vector multiplication).
It looks like in the current version alpha = 1 always, so one can just ignore it. I suspect that it will be added as an input parameter in future releases.

reverse engineering a checksum algorithm

I am all the time trying to determine how to reverse engineer this checksum. It should be a simple one, it is just a checksum for a firmware version of a device. Here are 5 hex-strings:
01854000ff1131050600323132393031323430344d45363438304330363730313835ffffffffffffffffffffffffffffffffffffffffffffffffffffff30303232313239303035353138303031485534355f4543455f4456445f535f4e00443120302e3120ff7beff9fff36fff7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff40b
01854000ff1029050600323132393031303830364d45373738304230373541303436ffffffffffffffffffffffffffffffffffffffffffffffffffffff30303132313239303036333133303031485534355f4543455f4456445f535f4e00443520302e3120ff7beff9fff36fff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffaa87
01854000ff1029050600323034393031323230334d45353135304238303830333132ffffffffffffffffffffffffffffffffffffffffffffffffffffff30303232303439303035393038303031485534355f4543455f4456445f535f4e00443520302e3120ff7beff9fff36fff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9e6a
01854000ff1131050600323436393031303330324d45363831304330363632333636ffffffffffffffffffffffffffffffffffffffffffffffffffffff30303332343639303036393038303031485534355f4543455f4456445f535f4e00443120302e3120ff7beff9fff36fff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe5d6
01854000ff1301050600323436393031343430344d45373435304430373132313239ffffffffffffffffffffffffffffffffffffffffffffffffffffff30303132343639303031333133303031485534355f4543455f4456445f535f4e00443520302e3120ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeb57
It looks like the last 2 bytes (4 hex-letters) are the checksum. I marked the differences in black.
Is anyone able to find out the algorithm, how the checksum is created? I tried already many things to find it out, but either I did it wrong or it didnĀ“t work.
My guess:
checksum(data) = CRC16-CCITT(data) XOR 0x6155
(which may be equivalent to another standard CRC16, I don't know)
See here for an online demo
Well it can be just about anything.. there are multiple implementation of crc, check for example these, I would apply those crcs on the data and compare their outputs to what you have ..

Why is spdiag deprecated in Octave, but not speye?

I've noticed that spdiag is deprecated, but not speye. Why is this? Both diag and eye generate diagonal matrices, so shouldn't speye be unnecessary as well (or at least exactly as unnecessary as spdiag)?
You must be using an old version of Octave if that function is deprecated. It has already been removed in the last 5 releases (all 5 minor versions since 3.6.0).
Anyway, to address your question spdiag() does not return a sparse matrix, it does exactly the same as diag(). To get a sparse diagonal matrix use spdiags().

octave runs ok but plot is not displayed?

HI there
I am using Octave 2.3.4 with a plot command. I am new at Octave. This plot does not display for some reason. Here is my M file sample:
1;
clear all;
%%%%%%%%% parameters setting %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
r=0.01; %risk free rate
S0=50; %underlying price 1
%create an implied volatiltiy surface using below parameters:
basevol=0.25; %implied volatility at time t=0 and in center of strike axis
skewT=-0.001; %icrease in vol for one unit increase in maturity
v1=0.1; %defines how much a smile is raised at left end from base vol
v3=0.2; %defines how much a smile is raised at right end from base vol
nK=100; %no. of strike steps
nT=10; %no. of time steps
Tmax=1; %maximum value in time axis
Kmin=1; %minimum value in strike price axis
Kmax=150; %maximum value of strike price axis
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
dt=Tmax/(nT-1);
Tvec=0:dt:1;
dk=(Kmax-Kmin)/(nK-1);
Kvec=Kmin:dk:Kmax;
Tvec=Tvec';
Kvec=Kvec';
nK=size(Kvec,1);
nT=size(Tvec,1);
dvolT=ones(nK,nT)*(skewT*dt);
dvolT=cumsum(dvolT,2);
SmileVec=GetSmile(Kvec,v1,0,v3);
dvolK=ones(nK,nT);
dvolK=repmat(SmileVec,1,nT);
ImpliedVolSurface=ones(nK,nT)*basevol+dvolT+dvolK;
%use formula mentioned by John Elder in "Hedging for Financial Derivatives"
%this formula gives local volatility using implied volatility
function ret=GetLocalVolSurface(ImpliedVolSurface, S, r, Kvec, Tvec)
[m,n]=size(ImpliedVolSurface);
LocalVolSurface=zeros(m,n);
dk=Kvec(2)-Kvec(1);
dt=Tvec(2)-Tvec(1);
x=ImpliedVolSurface;
for i=3:m-2, %loop over strikes
for j=1:n-1, %loop over time steps
dv_dk=(x(i+1,j)-x(i-1,j))/(2*dk);
dv2_dk2=(x(i-1,j)-2*x(i,j)+x(i+1,j))/(dk*dk);
dv_dt=(x(i,j+1)-x(i,j))/dt;
K=Kvec(i);
T=Tvec(j+1);
rT=T^0.5;
sig=x(i,j);
h1=(log(S/K)+r*T+0.5*sig*sig*T)/(sig*rT);
numer=sig*sig + 2*T*sig*dv_dt + 2*r*K*T*sig*dv_dk;
denom=(1+K*h1*rT*dv_dk)^2 + K*K*T*sig*sig*(dv2_dk2-h1*dv_dk*dv_dk*rT);
LocalVolSurface(i,j)=(numer/denom)^0.5;
end
end
ret=LocalVolSurface;
endfunction
LocalVol_Surface=GetLocalVolSurface(ImpliedVolSurface,S0,r,Kvec,Tvec);
AsyImplVols=zeros(nK,1);
T=Tvec(nT-1);
F=S0*exp(r*T);
for i=3:nK-2,
% use formula sigBS(F,K)=sigLoc( (F+K)/2 )
K=Kvec(i);
lookupK=(F+K)/2;
kdiff=abs(Kvec-lookupK); %try to find nearest point in grid
kidx=min(find(kdiff==min(kdiff)));
if ( (kidx > 3) && (kidx < nK-2) ),
AsyImplVols(i)=LocalVol_Surface(kidx);
else
AsyImplVols(i) = NaN;
end
end
figure(1);
plot(Kvec(3:nK-2),[ImpliedVolSurface(3:nK-2,nT-1) LocalVol_Surface(3:nK-2,nT-1) AsyImplVols(3:nK-2)]);
When I run in Octave with no error, the plot is never displayed. It does include gnuplot 1.0.1 which I understand does the graph? Is there something I am not doing or missing? I am also running this on Windows 2003 Server.
Thanks
I got the answer here. Octave by default uses fltk for plotting etc, which is failing to work, using gnuplot works here. Just add below lines to .octaverc file in your home directory.
graphics_toolkit("gnuplot")
So that every time octave starts it will set the default package for plotting to gnuplot
I do know that's an old question but since I ran into quite the same error yesterday, maybe this can help someone else, too:
According to the Octave wiki pages, there seems to be a problem with plotting and the "oct2mat"-library. For me, the problem was solved after I ran this at the octave command prompt:
pkg rebuild -noauto oct2mat
and restarted octave. When you need to use "oct2mat", type:
pkg load oct2mat
Hope that helps!
I get the same problem installing on a windows 7 64 bit laptop (HP 630) with intel graphics. Every time you plot, it fails to do anything, but if you plot again, it shows up. It's some kind of refresh bug. It's annoying, but if you plot twice, the second time it works.
I am wondering if it is some kind of double buffering bug, because it works correctly on my own laptop running windows 7 with a dedicated graphics card.
In any case, try plotting twice in a row, I'll bet it works, and please let me know what the machine and video card are, because I've reported this to octave development.