Command Reference : Function Reference : Function Reference: L
  
Function Reference: L
 
@lag
@last
@lastsby
@lasterrnum
@lasterrstr
@left
@len
@length
@linepath
@loadprgini
@localt
@log
log
@log10
@log1mexp
@log1p
@log2pi
@logcnorm
@logit
@logx
@lower
String
Matrix
@ltrim
@lu
@lag n-th order lag function.
@last The last non-missing value in the vector or series.
@lastsby Last non-missing value in a series for each specified group.
@lasterrnum Last error number generated by a previously issued command.
@lasterrstr Last error message generated by a previously issued command.
@left Left-hand characters in a string.
@len Length of a string.
@length Length of a string.
@linepath Location of the program file currently being executed.
@loadprgini Variable name value in an “.ini” file.
@localt Convert UTC (Coordinated Universal Time) to local time.
@log Natural logarithm function.
log Natural logarithm function.
@log10 Base-10 logarithm function.
@log1mexp Natural logarithm function of 1 minus exponential of argument.
@log1p Natural logarithm function of 1 plus argument.
@log2pi Natural logarithm of .
@logcnorm Natural logarithm of standard normal cumulative distribution.
@logit Logistic transform.
@logx Arbitrary base logarithm function.
@lower Lowercase representation of a string, or lower triangular matrix of a matrix.
@ltrim Trim left-whitespace from string.
@lu LU decomposition of a matrix.
@lag
n-th order lag function.
Syntax: @lag(x, n)
x: series, alpha, vector, svector, matrix object
n: series, alpha, vector, svector, matrix object
Return: series
Returns n-th order lag of the series, alpha, vector, svector, or columns of a matrix x. If n is not an integer, the integer floor will be used.
For a matrix x, the function will return a matrix of the same size with rows shifted down (or up if n is negative) n places. Unavailable rows will be filled with NAs.
This function is panel aware.
Examples
series y = 0
smpl @first+1 @last
y = @lag(y, 1) + @nrnd
smpl @all
The series y is a random walk process that starts at 0.
matrix(5,4) A
rnd(A)
matrix B = @lag(A,2)
Matrix A will be a matrix containing random uniform draws. Matrix B will have two rows of NAs, followed by the first three rows of A.
Cross-references
See also d.
@last
The last non-missing value in the data object.
Syntax: @last(o)
o: data object
Return: number or string
Returns a vector containing the last non-missing value of the single column data object. The series version uses the current workfile sample.
Examples
Let V be a vector of length 4 whose elements are 8.6, 0.3, NA, and NA. Then
= @last(v)
returns 0.3.
Cross-references
See also @cfirst, @clast, @cifirst, and @cilast.
See also @first, @ifirst, and @ilast.
@lastsby
Last non-missing value in a series for each specified group defined by distinct values.
Syntax: @lastsby(x, y[y1, y2, ... yn, s])
x: series, alpha
y1...yn series, alpha, group
s: (optional) sample string or object
Return: series, alpha
Last non-missing value in each distinct value group computed using the current workfile or specified sample.
Examples
show @lastsby(x, g1, g2)
produces a linked series of the by-group last non-missing values of the series x, where members of the same group have identical values for both g1 and g2.
Cross-references
See also @firstsby.
@lasterrnum
Last error number generated by a previously issued command.
Syntax: @lasterrnum
Return: integer
If a previous program line did not generate an error, the result will be a 0.
May only be used in a program.
Cross-references
See also @lasterrstr.
@lasterrstr
Last error message generated by the previously issued command.
Syntax: @lasterrstr
Return: string
If a program line did not generate an error, the result will be an empty string.
May only be used in a program.
Cross-references
See also @lasterrnum.
@left
Left hand characters in a string.
Syntax: @left(str, n)
str: string
n: integer
Return: string
Returns a string containing n characters from the left end of str. If the string is shorter than n characters, this function returns all of the characters in the source string.
Examples
The commands
string orig = "I did not do it"
string sc1 = @left("I did not do it", 5)
string sc2 = @left(orig, 5)
return the string objects SC1 and SC2 containing the string “I did”.
If ALPHA1 is an alpha series,
alpha a1 = @left(alpha1, 7)
returns the left-most 7 characters from the string values of ALPHA1 for each observation in the workfile sample.
If SVEC1 is an string vector,
svector s1 = @left(svec1, 12)
returns an svector containing 12 characters from the left end of each element of SVEC1.
Cross-references
See also @wleft, @right, and @mid.
@len
Length of a string
Syntax: @len(str)
str: string,
Return: integer
Returns integer values for the length of the string str.
Equivalent to @length.
Examples
The commands
string orig = "I did not do it"
@len("I did not do it")
@len(orig)
return the value 15.
If ALPHA1 is an alpha series,
series s1 = @len(alpha)
returns the length of the string values of ALPHA1 for each observation in the workfile sample.
If SVEC1 is an string vector,
vector v1 = @len(svec1)
returns a vector containing the length of each element of SVEC1.
Cross-references
See also @length.
@length
Length of a string.
Syntax: @length(str)
str: string
Return: integer
Returns integer values for the length of the string str.
Equivalent to @len.
Examples
The commands
string orig = "I did not do it"
@length("I did not do it")
@length(orig)
return the value 15.
If ALPHA1 is an alpha series,
series s1 = @length(alpha1)
returns the length of the string values of ALPHA1 for each observation in the workfile sample.
If SVEC1 is an string vector,
vector v1 = @length(svec1)
returns a vector containing the length of each element of SVEC1.
Cross-references
See also @length.
@linepath
Location of the program file currently being executed.
Syntax: @linepath
Return: string
If @linepath is being executed as a child program from a parent as part of an include or exec statement, the string will return the location of the child program.
Examples
If the program d:\myprogs\program1.prg has the line:
string y = @linepath
then y will contain “D:\MYPROGS\PROGRAM1.PRG”, no matter if program1 is run by itself, or as part of another program.
Cross-references
See also @runpath, @evpath and @temppath.
@loadprgini
Variable name value in an “.ini” file.
Syntax: @loadprgini("[section]name", "filename")
name: string
filename: string
section: (optional) string
Return: string
Returns a string containing the value of the specified variable name in the optionally specified section from the “.ini” file specified in filename. Both arguments must be enclosed in quotes.
If filename is not specified the default “.ini” is the one with the name of the current running program with extension “.ini.”
Note that the function returns a string, so to obtain a number you will have to convert the string using @val.
Examples
string val = @loadprgini("[section1]a", "myini.ini")
will save the value of “a” retrieved from section [section1] of the “.ini” file “myini.ini” located in your program file path.
Cross-references
See saveprgini.
@localt
Convert UTC (Coordinated Universal Time) to local time.
Syntax: @localt(utctime[, timezone])
utctime: date number, series, vector
timezone: (optional) timezone string
Return: date number, series, vector
Returns the local time zone representation of a point in time input in Coordinated Universal Time (UTC), utctime.
If timezone is not provided, the current Windows time zone setting is used as the local time zone target.
If timezone is provided, the timezone string can either contain raw time zone information in the format returned by @tzspec or it can contain search text (such as a city name) found within one of the time zone descriptions returned by the function @tzlist.
Examples
The commands
scalar dtime = @now
string london_spec = @tzspec("London")
@localtime(dtime, "+00:00 +01:00 Mar-1Sun 1:00 to Oct-1Sun 2:00")
@localtime(dtime, london_spec)
@localtime(dtime, "London")
give the date number for current London time. The first instance of @localtime uses the raw string for the London timezone string.
If UTC1 is a series containing UTC time values,
series tokyo_time = @localt(utc1, "Tokyo")
converts the values into equivalent local time values in Tokyo, for all observations in the workfile sample.
If UTC2 is a vector containing time values,
vector madrid_time = @localtime(utc2, "Madrid")
converts all date numbers in UTC2 into local Madrid time.
Additionally, if LOCSTR is a string vector containing timezone information
vector local_time = @localtime(@now, locstr)
converts the current time date number into the local time specified in the elements of LOCSTR.
Cross-references
See “Dates” and “Event Functions” for related discussion.
See also the related time zone functions @utc, @tz, @tzlist, and @tzspec.
@log
Natural logarithm function.
Syntax: @log(x)
x: number
Return: number
Returns for .
Examples
= @log(1.05)
returns 0.04879....
Cross-references
See log, @log1mexp, @log1p, @log10, @logx, @log2pi.
See also exp and @exp.
log
Natural logarithm function.
Syntax: log(x)
x: number
Return: number
Returns for .
Examples
= log(1.05)
returns 0.04879....
Cross-references
See @log, @log1mexp, @log1p, @log10, @logx, @log2pi.
See also exp and @exp.
@log10
Base-10 logarithm function.
Syntax: @log10(x)
x: number
Return: number
Returns for .
Examples
= @log10(100)
returns 2.
Cross-references
See log and @logx, @log2pi.
@log1mexp
Natural logarithm function of 1 minus exponential of argument.
Syntax: @log1mexp(x)
x: number
Return: number
Returns .
Provides higher-precision calculation of the expression for negative near 0 than direct evaluation using
@log(1 - @exp(x))
Examples
= @log1mexp(-0.05)
returns -3.02062....
Cross-references
See @log, @log1p, @log10, @logx, @log2pi.
See also exp and @exp.
@log1p
Natural logarithm function of 1 plus argument.
Syntax: @log1p(x)
x: number
Return: number
Returns .
Provides higher precision calculation of the expression for near 0 than direct evaluation using
@log(1 + x)
Examples
= @log1p(0.05)
returns 0.04879....
Cross-references
See @log,, @log1p, @log10, @logx, @log2pi.
See also exp and @exp.
@log2pi
Natural logarithm of .
Syntax: @log2pi
Return: number
Examples
= @log2pi
returns 1.83787....
Cross-references
See also @log and log.
@logcnorm
Natural logarithm of standard normal cumulative distribution.
Syntax: @logcnorm(x[, u])
x: number
u: (optional) number
Return: number
Computes the natural logarithm of the cumulative distribution integral
where
If the optional argument u is non-zero, return the logarithm of the upper-tail cumulative distribution value: .
Examples
= @logcnorm(-1.96)
returns -3.68896... (the natural log of 0.02499...).
Cross-references
See also @cnorm, @dnorm, @qnorm, and @rnorm.
@logit
Logistic transform.
Syntax: @logit(x[, u])
x: number
u: (optional) number
Return: number
Computes the logistic function:
If the optional argument u is non-zero, return the upper-tail value:
Examples
= @logit(.3)
returns 0.57444.
= @logit(.3, 1)
returns 0.42556.
Cross-references
See also @clogistic, @dlogistic, @qlogistic, and @rlogistic.
@logx
Arbitrary base logarithm function.
Returns the b-base logarithm of x.
Syntax: @logx(x, b)
x: number
b: number
Return: number
for .
Examples
= @logx(256,2)
returns 8.
Cross-references
See also @log, log, @log1mexp, @log1p, @log10, and @log2pi.
@lower
Lowercase representation of a string.
Syntax: @lower(str)
str: string, alpha, svector
Return: string, alpha, svector
Returns the lowercase representation of the string str.
Lower triangular matrix of a matrix.
Syntax: @lower(m[, n])
m: matrix, sym
n (optional) integer
Return: matrix
Returns a matrix whose elements on and below the n-th diagonal match the corresponding elements of the matrix m, but whose elements above the n-th diagonal are zero.
By default, n is has a value of zero, indicating the main diagonal. Positive values of n indicate super-diagonals, while negative values of k indicate sub-diagonals.
Examples
String
If we define the string object
string s1 = "I did NOT do it"
the commands
@lower("I did NOT do it")
@lower(s1)
return the string “i did not do it”.
If ALPHA1 is an alpha series,
alpha alphalwr = @lower(alpha1)
returns the lowercase of the strings in ALPHA1 for each observation in the workfile sample.
If SVEC1 is an string vector,
svector sveclen = @lower(svec1)
returns a string vector containing the lowercased elements of SVEC1.
Matrix
The commands
matrix(3,3) m1
m1.fill 1, 2, 3, 4, 5, 6, 7, 8, 9
matrix l1 = @lower(m1)
matrix l2 = @lower(m1, 1)
matrix l3 = @lower(m1, -1)
create a matrix M1
the matrix L1 containing,
the matrix L2 containing,
and the matrix L3 containing
If we have the commands,
sym s = @rwish(@identity(5), 5)
matrix s1 = @lower(s)
matrix s2 = @lower(s, -1)
then S is a sym matrix and S1 is a lower triangular matrix with elements at or below the main diagonal equal to those in S, and elements below the main diagonal equal to zero. S2 is a strictly lower triangular matrix that is equal to S1, but with the main diagonal elements also set to 0.
Cross-references
See also @upper.
@ltrim
Trim left whitespace of a string.
Syntax: @ltrim(str)
tr: string, alpha, svector
Return: string, alpha, svector
Returns the string str with spaces trimmed from the left.
Examples
@ltrim(" I doubt that I did it.  ")
returns “I doubt that I did it.  ”. Note that the spaces on the right remain.
If ALPHA1 is an alpha series,
alpha alphaltrim = @ltrim(alpha1)
returns the left-trimmed strings in ALPHA1 for each observation in the workfile sample.
If SVEC1 is an string vector,
svector sveclen = @ltrim(svec1)
returns a string vector containing the left-trimmed elements of SVEC1.
Cross-references
See also @rtrim and @trim.
@lu
LU decomposition of matrix.
Syntax: @lu(M, L, U)
M: matrix
L: matrix
U: matrix
Return: matrix (P)
Performs an LU decomposition with partial (row) pivoting of the matrix M:
if M is a square produce a unit lower triangular matrix, L, an upper triangular matrix, U, and a row permutation matrix, P, such that .
if M is a non-square matrix, if , L will be unit lower trapezoidal (rather than triangular), and if , U will be upper trapezoidal (rather than triangular).
Examples
matrix m = @mnrnd(10, 8)
matrix lmat
matrix umat
matrix pmat = @lu(m, lmat, umat)
generates the random matrix M, then performs the LU decomposition returning PMAT and yielding updated LMAT, UMAT.
The following commands validate the definition
matrix m1 = pmat * lmat * umat
matrix diff = m - m1
since DIFF equals zero.
Cross-references
See also @cholesky, @qr, @svd and @svdfull.