I know I can use the b() option in the community-contributed command esttab to control the number of decimal points displayed in the rows (i.e. the regressors):
estimates clear
eststo clear
sysuse auto, clear
eststo w1: regress price mpg trunk length
eststo w2: regress turn mpg trunk length
eststo w3: regress displacement mpg trunk length
esttab, b(1 3 5)
All of the decimal points in the first row (mpg) have one decimal point. The second and third rows have three and five decimal points.
However, instead of controlling the decimal points by row, I want to control the number of decimal points by column (model).
Is there a way to do this?
For example, I want all of the regressors in the first column to have one decimal point, all of the regressors in the second column to have three decimal points, and all of the regressors in the third column to have five decimal points.
You cannot do this directly but a workaround is to use a matrix.
A simple example is the following:
matrix A = ( -173.70800, -0.06556, -1.77658 \ ///
-0.85469, -0.05926, 0.06587 \ ///
21.40414, 0.16548, 3.06799 \ ///
5853.99300, 10.76202, -342.34697 )
matrix rownames A = mpg trunk length _cons
esttab matrix(A, fmt(1 3 5)), gaps mlabel(none) ///
collabels("price" "turn" "displacement")
---------------------------------------------------
price turn displacement
---------------------------------------------------
mpg -173.7 -0.066 -1.77658
trunk -0.9 -0.059 0.06587
length 21.4 0.165 3.06799
_cons 5854.0 10.762 -342.34697
---------------------------------------------------
Related
I have created a table where a column has the format NUMBER(2,3).
I try to insert the value 5.73 but it doesn't work.
The error is :
ORA-01438 - "value larger than specified precision allowed for this column"
Cause: When inserting or updating records, a numeric value was entered
that exceeded the precision defined for the column.*
I read the documentation but i don't understand the scale.
So, what is the format accepted value 0-99 with 3 values after the decimal point ?
Thanks.
You are misunderstanding precision and scale. You have a number with a precision of 2. That means that there are two significant digits. It has a scale of 3, which means that these are to the right of the decimal point.
So, your column can represent values between 0.000 and 0.099
What you want is NUMERIC(5, 3). "precision - scale" is the number of digits to the left of the decimal point.
This has come from here:
https://docs.oracle.com/cd/B28359_01/server.111/b28318/datatype.htm#CNCPT1832
Optionally, you can also specify a precision (total number of digits) and scale (number of >digits to the right of the decimal point):
column_name NUMBER (precision, scale)
So in your example you are allowed a total number of 2 digits ( and 3 digits to the right of the decimal point). Which doesn't work for 5.73, perhaps you need a type of number(3,2) which would allow 3 digits 2 of which can be right of the decimal point.
Given an integer n such that (1<=n<=10^18)
We need to calculate f(1)+f(2)+f(3)+f(4)+....+f(n).
f(x) is given as :-
Say, x = 1112222333,
then f(x)=1002000300.
Whenever we see a contiguous subsequence of same numbers, we replace it with the first number and zeroes all behind it.
Formally, f(x) = Sum over all (first element of the contiguous subsequence * 10^i ), where i is the index of first element from left of a particular contiguous subsequence.
f(x)=1*10^9 + 2*10^6 + 3*10^2 = 1002000300.
In, x=1112222333,
Element at index '9':-1
and so on...
We follow zero based indexing :-)
For, x=1234.
Element at index-'0':-4,element at index -'1':3,element at index '2':-2,element at index 3:-1
How to calculate f(1)+f(2)+f(3)+....+f(n)?
I want to generate an algorithm which calculates this sum efficiently.
There is nothing to calculate.
Multiplying each position in the array od numbers will yeild thebsame number.
So all you want to do is end up with 0s on a repeated number
IE lets populate some static values in an array in psuedo code
$As[1]='0'
$As[2]='00'
$As[3]='000'
...etc
$As[18]='000000000000000000'```
these are the "results" of 10^index
Given a value n of `1234`
```1&000 + 2&00 +3 & 0 + 4```
Results in `1234`
So, if you are putting this on a chip, then probably your most efficient method is to do a bitwise XOR between each register and the next up the line as a single operation
Then you will have 0s in all the spots you care about, and just retrive the values in the registers with a 1
In code, I think it would be most efficient to do the following
```$n = arbitrary value 11223334
$x=$n*10
$zeros=($x-$n)/10```
Okay yeah we can just do bit shifting to get a value like 100200300400 etc.
To approach this problem, it could help to begin with one digit numbers and see what sum you get.
I mean like this:
Let's say, we define , then we have:
F(1)= 45 # =10*9/2 by Euler's sum formula
F(2)= F(1)*9 + F(1)*100 # F(1)*9 is the part that comes from the last digit
# because for each of the 10 possible digits in the
# first position, we have 9 digits in the last
# because both can't be equal and so one out of ten
# becomse zero. F(1)*100 comes from the leading digit
# which is multiplied by 100 (10 because we add the
# second digit and another factor of 10 because we
# get the digit ten times in that position)
If you now continue with this scheme, for k>=1 in general you get
F(k+1)= F(k)*100+10^(k-1)*45*9
The rest is probably straightforward.
Can you tell me, which Hackerrank task this is? I guess one of the Project Euler tasks right?
I have a Python list in which each row contains two columns. The first column contains a real number (th) and the second column contains a complex number (voltage).
0.25 (1.2457255255383563e-09 - 7.827999559008199e-11j)
0.225 (1.2769209019868422e-09 - 1.1957504414521587e-10j)
0.2 (1.3221477572417824e-09 - 1.6359636324117563e-10j)
0.175 (1.382055160135606e-09 - 2.0572240011775488e-10j)
0.125 (1.5471711559849657e-09 - 2.696133396356665e-10j)
0.075 (1.787743723105496e-09 - 2.8204767576743745e-10j)
0.025 (2.0887332185896165e-09 - 2.0611142376588599e-10j)
I want to plot these voltages on a polar plane, labelled with their corresponding th values.
Using the following code, where data is the table I have shown above:
def th_polar_plots(data):
th = []
vreal = []
vim = []
for row in data:
th.append(row[0])
voltage = complex(row[1])
vreal.append(voltage.real)
vim.append(voltage.imag)
plt.polar(th, vreal, 'ro-', th, vim, 'bo-')
plt.show()
I am able to generate this:
Not only is this incorrect, but it also fails to make any sense to me. Because what I need is each voltage vector with a dot/circle on it for the th value, since in the future I would need to plot more such th vs voltage tables in the same plane for comparison.
Edit: I have formatted the spacing and indentation in the table for better readability.
Your radius is wrong in the plt.polar() call. Try the following in your code,
radius = np.sqrt(voltage.real**2 + voltage.imag**2)
plt.polar(th, radius, 'ro-')
I am trying to calculate the slope of the line for a 50 day EMA I created from the adjusted closing price on a few stocks I downloaded using the getSymbols function.
My EMA looks like this :
getSymbols("COLUM.CO")
COLUM.CO$EMA <- EMA(COLUM.CO[,6],n=50)
This gives me an extra column that contains the 50 day EMA on the adjusted closing price. Now I would like to include an additional column that contains the slope of this line. I'm sure it's a fairly easy answer, but I would really appreciate some help on this. Thank you in advance.
A good way to do this is with rolling least squares regression. rollSFM does a fast and efficient job for computing the slope of a series. It usually makes sense to look at the slope in relation to units of price activity in time (bars), so x can simply be equally spaced points.
The only tricky part is working out an effective value of n, the length of the window over which you fit the slope.
library(quantmod)
getSymbols("AAPL")
AAPL$EMA <- EMA(Ad(AAPL),n=50)
# Compute slope over 50 bar lookback:
AAPL <- merge(AAPL, rollSFM(Ra = AAPL[, "EMA"],
Rb = 1:nrow(AAPL), n = 50))
The column labeled beta contains the rolling window value of the slope (alpha contains the intercept, r.squared contains the R2 value).
I bootstrapped my own p-values for a regression and now need to add them to my esttab table. I would ideally like the p-values to appear immediately below the coefficient point estimates. While I am able to place the new p-values into my table, they appear in the table is if they arenew point estimates with labels c1, c2, etc.
Here is the relevant simplified code (following the regression) where the bootstrapped p-value is in the local newpvalue
matrix pval = (`newpvalue')
estadd matrix Puse = pval
esttab , replace cells(b(star fmt(3)) Puse(fmt(3) par) )
This code produces the standard table, but with the p-value placed several spaces below the coefficient estimate. Thanks very much for any help, and please let me know if the question is not clear.
An example that might help (with in-line comments):
clear
set more off
*----- example data -----
sysuse auto
keep price weight mpg
*----- what you want -----
//regress and store
reg price weight mpg
eststo m1
// create matrix of "scalars"
matrix s = (2.1 , 2.4 , 3.2)
// rename matrix columns to coincide with those of regression
mat colnames s = weight mpg _cons
// add
estadd matrix s
// print
estout m1, cells(b s)
Very similar to: Stata: combining regression results with other results but notice the absence of quotes in the last line of code.