There seems to be no margin whatsoever even though I explicitly set the margin between the image and title to be 12dp
What am I missing?
Setting the heights to Dimension.value(0dp) did not do the trick btw
My view component:
#Preview
#Composable
fun GenericEmptyState() {
MaterialTheme() {
ConstraintLayout(
Modifier
.fillMaxSize(1f)
.background(Color.White)
.padding(24.dp)
) {
val (image, title, text, cta) = createRefs()
Image(
painterResource(R.drawable.hearts),
contentDescription = "hearts",
modifier = Modifier.constrainAs(image) {
top.linkTo(parent.top)
start.linkTo(parent.start)
end.linkTo(parent.end)
height = Dimension.value(150.dp)
width = Dimension.value(150.dp)
}
)
Text(
"this is the title",
Modifier.constrainAs(title) {
top.linkTo(image.bottom, 12.dp)
start.linkTo(parent.start)
end.linkTo(parent.end)
height = Dimension.wrapContent
})
Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat",
Modifier.constrainAs(text) {
top.linkTo(title.bottom, 12.dp)
start.linkTo(parent.start)
end.linkTo(parent.end)
}
)
createVerticalChain(image, title, text, chainStyle = ChainStyle.Packed(0.5f))
}
}
}
Compose version 1.0.5
I've had a similar case. If anyone do the following, can solve the problem
...
Text(
"this is the title",
Modifier
// First, set padding above constrainAs
.padding(top = 12.dp)
.constrainAs(title) {
// Remove margin value
top.linkTo(image.bottom)
start.linkTo(parent.start)
end.linkTo(parent.end)
height = Dimension.wrapContent
})
Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat",
Modifier
// set padding top too
.padding(top = 12.dp)
.constrainAs(text) {
// Remove margin value
top.linkTo(title.bottom)
start.linkTo(parent.start)
end.linkTo(parent.end)
})
...
Since Modifier processes layout sequentially, so if padding is set first, the calculated size is used.
You're not using createVerticalChain as intended. I haven't found this function description in Compose documentation - seems it's still under development, but androidx.constraintlayout.widget documentation (on which Compose ConstraintLayout should be based) contains the following description:
This operation sets all the related margins to 0.
Removing this line solves your problem.
Also Here's how you can build the same layout without ConstraintLayout:
Use Column to place items.
Space items by 12.dp using arrangement
Center items using alignment
Column(
verticalArrangement = Arrangement.spacedBy(12.dp),
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier
.fillMaxSize(1f)
.background(Color.White)
.padding(24.dp)
) {
Image(
painterResource(R.drawable.my_image_2),
contentDescription = "hearts",
modifier = Modifier
.size(150.dp)
)
Text("this is the title")
Text(LoremIpsum(30).values.first())
}
In order to use margins you should ultilize different method overload.
ConstraintLayout compose has linkTo method with a margin and goneMargin parameters. You can set them.
fun linkTo(
anchor: ConstraintLayoutBaseScope.VerticalAnchor,
margin: Dp = 0.dp,
goneMargin: Dp = 0.dp
)
Example:
Text(modifier = Modifier
.constrainAs(publisher) {
start.linkTo(text2.end, margin = 8.dp)
},
)
Related
As defined in the image, xAxis's texts are going off from the blue rectangle below the xAxis.
Is it possible to make the text auto resizable to always fit inside the defined rectangle inrespect of defined textSize?
val xPoints: List<String> = listOf(
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
)
Canvas(
modifier = modifier
.fillMaxWidth()
) {
val rectWidth = (size.width - leftPadding - rightPadding) / xPoints.size
//Draw x-Axis Text
xPoints.forEachIndexed { index, text ->
val offset = Offset(
0f + leftPadding + (index * rectWidth) + (rectWidth / 2),
graphHeight - (bottomPadding / 2)
)
val rect = Rect(offset, rectWidth / 2)
drawRect(
color = Color.Red,
Offset(0f + leftPadding + (index * rectWidth), graphHeight - bottomPadding)
, size = Size(rectWidth, bottomPadding)
)
rotate(degrees = -45f, rect.center) {
drawIntoCanvas {
it.nativeCanvas.drawText(
text,
rect.center.x,
rect.center.y,
xAxisTextPaint
)
}
}
}
}
One possibility would be to use SubcomposeLayout to first measure the composable in one slot, then calculate the desired scale factor and use it to wrap the composable in another composable with a scale modifier, and finally, layout the scaled composable in another layout slot.
How to create a clongtable that spans over multiple pages with page width in a document of two columns page?
I have this so far:
\documentclass[final,3p,times,twocolumn,authoryear]{elsarticle}
\usepackage{graphicx}
\usepackage{adjustbox}
\usepackage[usestackEOL]{stackengine}
\usepackage{multirow}
\usepackage{longtable, tabu}
\usepackage{tabularray}
\usepackage{lscape}
\usepackage{tabularx}
\usepackage[table]{xcolor}
\definecolor{aliceblue}{rgb}{0.94, 0.97, 1.0}
\definecolor{cornsilk}{rgb}{1.0, 0.97, 0.86}
\definecolor{eggshell}{rgb}{0.94, 0.92, 0.84}
\definecolor{floralwhite}{rgb}{1.0, 0.98, 0.94}
\definecolor{anti-flashwhite}{rgb}{0.95, 0.95, 0.96}
\definecolor{ivory}{rgb}{1.0, 1.0, 0.94}
\definecolor{lightyellow}{rgb}{1.0, 1.0, 0.88}
\definecolor{splashedwhite}{rgb}{1.0, 0.99, 1.0}
\definecolor{snow}{rgb}{1.0, 0.98, 0.98}
\definecolor{white}{rgb}{1.0, 1.0, 1.0}
\definecolor{whitesmoke}{rgb}{0.96, 0.96, 0.96}
\begin{longtblr}[
caption = {Long table over multiple pages},
label = {rct-tab},
]{
colspec = {p{1.4cm} p{2.5cm} p{1.4cm} p{1.8cm} p{1.4cm} p{0.9cm} },
rowhead = 1,
hlines,
row{even} = {whitesmoke},
row{odd} = {white},
row{1} = {floralwhite},
}
ID & P1 & P2 & P3 & P4 & P5 \\
1 & x, age $\geq$ 18 & 62 (58) & 17.7\% (10.3\%) & 3 months & TY \\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
\end{longtblr}
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
This code works fine and spreads the table over multiple pages but it shows up over the text. I think it is a floating problem. So when placed in a page with two-column it goes over the text.
If you don't mind having a page break before and after your table, you could temporarily switch to one column mode:
\documentclass[final,3p,times,twocolumn,authoryear]{elsarticle}
\usepackage{graphicx}
\usepackage{adjustbox}
\usepackage[usestackEOL]{stackengine}
\usepackage{multirow}
\usepackage{longtable, tabu}
\usepackage{tabularray}
\usepackage{lscape}
\usepackage{tabularx}
\usepackage[table]{xcolor}
\definecolor{aliceblue}{rgb}{0.94, 0.97, 1.0}
\definecolor{cornsilk}{rgb}{1.0, 0.97, 0.86}
\definecolor{eggshell}{rgb}{0.94, 0.92, 0.84}
\definecolor{floralwhite}{rgb}{1.0, 0.98, 0.94}
\definecolor{anti-flashwhite}{rgb}{0.95, 0.95, 0.96}
\definecolor{ivory}{rgb}{1.0, 1.0, 0.94}
\definecolor{lightyellow}{rgb}{1.0, 1.0, 0.88}
\definecolor{splashedwhite}{rgb}{1.0, 0.99, 1.0}
\definecolor{snow}{rgb}{1.0, 0.98, 0.98}
\definecolor{white}{rgb}{1.0, 1.0, 1.0}
\definecolor{whitesmoke}{rgb}{0.96, 0.96, 0.96}
\usepackage{lipsum}
\usepackage{afterpage}
\begin{document}
\lipsum[1-5]
\afterpage{
\onecolumn
\begin{longtblr}[
caption = {Long table over multiple pages},
label = {rct-tab},
]{
colspec = {p{1.4cm} p{2.5cm} p{1.4cm} p{1.8cm} p{1.4cm} p{0.9cm} },
rowhead = 1,
hlines,
row{even} = {whitesmoke},
row{odd} = {white},
row{1} = {floralwhite},
}
ID & P1 & P2 & P3 & P4 & P5 \\
1 & x, age $\geq$ 18 & 62 (58) & 17.7\% (10.3\%) & 3 months & TY \\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip\\
minim & veniam quis & nostrud exercitation & ullamco & laboris & nisi ut & aliquip
\end{longtblr}
\twocolumn
}
\lipsum
\end{document}
How to save table output from Stata's pstest
I want to save the output from Stata's pstest command with the option both after running psmatch2. I use pstest in a loop that produces hundreds of tables so copying and pasting individual tables from the screen isn't practical. I've seen this question asked elsewhere, but I haven't seen a workable solution. putdocx does not work to the best of my knowledge.
My question
My solution below works if the options logit, k-nearest neighbour matching (where k = 5), Abadie and Imbens standard errors, average treatment effects and common support are chosen for psmatch2 (logit n(5) ai(5) ate common) and both is the option chosen for the subsequent pstest command, like so pstest, both atu. Is there a better, more flexible solution that doesn't require re-writing my code if any of these options change?
To be clear, I'm not looking for anyone to edit my code. My solution works but is long and difficult to revise if different options are specified. A better answer would be simpler, much shorter, and flexible enough to show results when different options are chosen. A solution using putdocx would be ideal.
A suggestion
If it is possible, I would suggest that Stata consider requiring authors of packages to make any output to the screen retrievable in some way, perhaps using return list or ereturn list. Only the last table produced using pstest can be retrieved this way. I believe, pstest saves the output in the first of two tables in temporary memory, which is lost when the second table is created. Output from the second is available to users via return list. If I am mistaken about this, please let me know.
My solution, so far
This code works, but it is more of a workaround than a solution. In the absence of something better, I hope it will help anyone in a bind similar to the one in which I found myself.
* Most of this code is from the pstest.ado by Leuven and Sianesi (2003)
clear all
set more off
* Define the program to generate output from the Stata command pstest
cap program drop pstest_tab
program define pstest_tables
args exog atu
/* _weight is conditional on ATU option */
qui replace _weight = _support if _treated==0
local i = 0
local cont_cnt = 0 /* counting continuous vars */
local cont_varbef = 0 /* counting continuous vars w/ excessive var ratio*/
local cont_varaft = 0
qui g _bias0 = .
qui g _biasm = .
qui g sumbias = .
qui g sumbias0 = .
scalar wd_num = `:word count `exog''
mat A = J(wd_num,13,.)
mat R = J(1,16,.)
qui count if _treated==1 & esample==1
scalar Flowu = invF(r(N)-1, r(N)-1, 0.025)
scalar Fhighu = invF(r(N)-1, r(N)-1, 0.975)
qui count if _treated==1 & _support==1 & esample==1
scalar Flowm = invF(r(N)-1, r(N)-1, 0.025)
scalar Fhighm = invF(r(N)-1, r(N)-1, 0.975)
foreach v of local exog {
local ++i
/* Calculate stats for varlist */
qui sum `v' if _treated==1
scalar m1u = r(mean)
scalar v1u = r(Var)
mat A[`i',1] = r(mean)
qui sum `v' if _treated==0
scalar m0u = r(mean)
scalar v0u = r(Var)
mat A[`i',2] = r(mean)
qui sum `v' [iw=_weight] if _treated==1 & _support==1 & esample==1
scalar m1m = r(mean)
scalar v1m = r(Var)
mat A[`i',3] = r(mean)
qui sum `v' if _treated==0 & _support==1 & esample==1
scalar m0m = r(mean)
scalar v0m = r(Var)
mat A[`i',4] = r(mean)
/* Get Var ratio */
scalar v_ratiobef = v1u/v0u
scalar v_ratioaft = v1m/v0m
mat A[`i',12] = v1u/v0u
mat A[`i',13] = v1m/v0m
/* Get Var ratio */
capture assert `v'==0 | `v'==1 | `v'==., fast
if (_rc) {
local cont_cnt = `cont_cnt' +1
scalar v_ratiobef = v1u/v0u
if v_ratiobef>Fhighu | v_ratiobef<Flowu {
local cont_varbef = `cont_varbef' +1
}
scalar v_ratioaft = v1m/v0m
if v_ratioaft>Fhighm | v_ratioaft<Flowm {
local cont_varaft = `cont_varaft' +1
}
}
/* Standardised bias before matching */
scalar bias = 100*(m1u - m0u)/sqrt((v1u + v0u)/2)
mat A[`i',5] = bias
qui replace _bias0 = bias in `i'
qui replace sumbias0 = abs(bias) in `i'
/* Standardised bias after matching */
scalar biasm = 100*(m1m - m0m)/sqrt((v1u + v0u)/2)
mat A[`i',6] = biasm
qui replace _biasm = biasm in `i'
qui replace sumbias = abs(biasm) in `i'
/* Reduction in absolute bias */
mat A[`i',7] = -100*(abs(biasm) - abs(bias))/abs(bias)
/* t-tests before matching */
qui regress `v' _treated
mat A[`i',8] = _b[_treated]/_se[_treated]
mat A[`i',9] = 2*ttail(e(df_r),abs(_b[_treated]/_se[_treated]))
/* t-tests after matching */
qui regress `v' _treated [iw=_weight] if _support==1 & esample==1
mat A[`i',10] = _b[_treated]/_se[_treated] //taft
mat A[`i',11] = 2*ttail(e(df_r),abs(_b[_treated]/_se[_treated])) //paft
scalar vrb = 100*`cont_varbef'/`cont_cnt'
scalar vra = 100*`cont_varaft'/`cont_cnt'
}
/* Get overall stats for the second table */
qui probit _treated `exog' if esample==1
qui predict double index0 if e(sample), xb
mat R[1,1] = e(r2_p) // r2bef
mat R[1,3] = e(chi2) // chibef new
mat R[1,5] = chi2tail(e(df_m), e(chi2)) // probbef
qui probit _treated `exog' [iw=_weight] if _support==1 & esample==1
qui predict double indexm if e(sample), xb
mat R[1,2] = e(r2_p) // r2aft
mat R[1,4] = e(chi2) // chibef
mat R[1,6] = chi2tail(e(df_m), e(chi2)) //probaft
qui replace _bias0 = bias in `i'
qui replace sumbias0 = abs(bias) in `i'
qui replace _biasm = biasm in `i'
qui replace sumbias = abs(biasm) in `i'
qui sum sumbias0, detail
mat R[1,7] = r(mean) // meanbiasbef
mat R[1,9] = r(p50) // medbiasbef
qui sum sumbias, detail
mat R[1,8] = r(mean) // meanbiasaft
mat R[1,10] = r(p50) // medbiasaft
qui sum index0 if _treated==1 & esample==1
scalar mi1 = r(mean)
scalar vi1 = r(Var)
qui sum index0 if _treated==0 & esample==1
scalar mi0 = r(mean)
scalar vi0 = r(Var)
mat R[1,11] = 100*(mi1 - mi0)/sqrt((vi1 + vi0)/2) // ibiasbef
mat R[1,13] = vi1/vi0 // iratiobef
qui sum indexm [iw=_weight] if _treated==1 & _support==1 & esample==1
scalar mi1 = r(mean)
scalar vi1 = r(Var)
qui sum indexm [iw=_weight] if _treated==0 & _support==1 & esample==1
scalar mi0 = r(mean)
scalar vi0 = r(Var)
mat R[1,12] = 100*(mi1 - mi0)/sqrt((vi1 + vi0)/2) // ibiasaft
mat R[1,14] = vi1/vi0 // iratioaft
mat R[1,15] = 100*`cont_varbef'/`cont_cnt'
mat R[1,16] = 100*`cont_varaft'/`cont_cnt'
end
* Get example dataset
webuse cattaneo2, clear
* Keep only the used variables
keep mbsmoke foreign alcohol mage medu fage fedu bweight
* Run psmatch2
qui psmatch2 mbsmoke foreign alcohol mage medu fage fedu, out(bweight) logit n(5) ai(5) ate common
qui gen esample=e(sample)
mat P=J(1,13,.)
local xvars foreign alcohol mage medu fage fedu
pstest_tables "`xvars'" "`r(atu)'"
* Run the pstest_tables function
qui psmatch2 mbsmoke foreign alcohol mage medu fage fedu, out(bweight) logit n(5) ai(5) ate common
pstest, both atu
mat li A
mat li R
matrix colnames R = "R2(U)" "R2(M)" "LRchi2(U)" "p>chi2(U)" "MeanBias(U)" "MedBias(U)" "B(U)" ///
"R(U)" "%Var(U)" "LRchi2(M)" "p>chi2(M)" "MeanBias(M)" "MedBias(M)" "B(M)" "R(M)" "%Var(M)"
* Reshape the matrix to resemble the tables from pstest
mat B = A[1..6,1..4]
mata : M = colshape(st_matrix("B"),2)
mata : st_matrix("B",M)
mat C = A[1..6,5..6]
mata: M = colshape(st_matrix("C"),1)
mata : st_matrix("C",M)
mat D = J(12,1,.)
mat D[2,1] = A[1,7]
mat D[4,1] = A[2,7]
mat D[6,1] = A[3,7]
mat D[8,1] = A[4,7]
mat D[10,1] = A[5,7]
mat D[12,1] = A[6,7]
mat E = A[1..6,8..11]
mata: M = colshape(st_matrix("E"),2)
mata : st_matrix("E",M)
mat F = A[1..6,12..13]
mata: M = colshape(st_matrix("F"),1)
mata : st_matrix("F",M)
mat G = B,C,D,E,F
mata: M = colshape(st_matrix("R"),2)
mata: st_matrix("R",M)
mat R = R'
mat li R
matrix colnames R = "Ps R2" "LR chi2" "p>chi2" "MeanBias" "MedBias" "B" "R" "%Var"
matrix rownames R = "Unmatched" "Matched"
matrix colnames G = "Treated" "Control" "%bias" "%red_bias" "t" "p>|t|" "V(T)/V(C)"
matrix rownames G = "foreign (U)" "foreign (M)" "alcohol (U)" "alcohol (M)" "mage (U)" ///
"mage (M)" "medu (U)" "medu (M)" "fage (U)" "fage (M)" "fedu (U)" "fedu (M)"
estout mat(G, fmt(3))
mat li R, format(%4.3f)
qui psmatch2 mbsmoke foreign alcohol mage medu fage fedu, out(bweight) logit n(5) ai(5) ate common
pstest, both atu
I'm currently using some matching techniques and had the same question. One shortcut I found is using 'asdoc'.
I used:
"asdoc pstest v1 v2 v3"
asdoc created a word document called myfile in your working directory and from there you might take the table and transform into latex maybe. I haven't found a better way yet, but thought if it comes handy to you somehow.
Good luck with your work! :)
How can I create line breaks within a long Text widget?
For example, I am creating a biographical page about myself. And I have three paragraphs I want to be able to display. But currently, I am outputting those paragraphs in one big Text Widget and the output does not have line breaks to differentiate the paragraphs. How can I do that?
declare your text like so:
final String someText =
"stuff for the 1st paragraph\n\n"
"stuff for the 2nd paragraph\n\n"
"stuff for the 3rd paragraph\n\n";
and then you can just render it inside of a Text widget like you normally would.
I came here wanting to divide a long string in code over multiple lines. Starting with this:
final longString = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.';
Multi-line without new lines
You can make it all visible in your code editor by doing this:
final longString = 'Lorem ipsum dolor sit amet, consectetur adipiscing '
'elit, sed do eiusmod tempor incididunt ut labore et dolore magna '
'aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco '
'laboris nisi ut aliquip ex ea commodo consequat. ';
or this:
final longString = 'Lorem ipsum dolor sit amet, consectetur adipiscing ' +
'elit, sed do eiusmod tempor incididunt ut labore et dolore magna ' +
'aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco ' +
'laboris nisi ut aliquip ex ea commodo consequat.';
without affecting the content of the string. That is, no newline characters will be added.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Multi-line with new lines
If you actually do want the line breaks to stay, then you can use triple quotes.
final longString = '''
Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua.
Ut enim ad minim veniam,
quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea
commodo consequat.
''';
which produces:
Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua.
Ut enim ad minim veniam,
quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea
commodo consequat.
Dividing paragraphs
As has already been mentioned, just add two \n newline characters to every paragraph to separate them. Or a \t tab at the beginning and a newline at the end.
final paragraph1 = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.';
final paragraph2 = 'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.';
final text = paragraph1 + '\n\n' + paragraph2;
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
If you are doing a lot of string concatenation, then consider using StringBuffer.
See also
Meaning of Paragraph in Flutter classes
I'm assuming you already have some way in the original text to tell that there should be a line break such as \n. If your paragraph is something like: var text = "paragraph1\n\nparagraph2";, you could do something like the following:
var split = text.split('\n').map((i) {
if (i == "") {
return Divider();
} else {
return Text(i);
}
}).toList();
var displayElement = Column(children: split);
returning the displayElement, which will have a divider element between each paragraph.
In one slide, I find that two paragraphs are too close vertically. Then I want extra space. However, I find that applying more \ \ does not work in beamer.
Try inserting vertical space using \vspace, e.g. \vspace{1cm}.
See https://en.wikibooks.org/wiki/LaTeX/Lengths for more details.
Not a trivial question: see this TeX.SE post and this other.
The way to set the default parskip may be the following:
\documentclass{beamer}
%\usetheme{CambridgeUS}
\usepackage[english]{babel}
\parskip=20pt
\begin{document}
\begin{frame}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat.
\end{frame}
\end{document}
Otherwise, if you want to change the parskip only locally (as I seem to understand), you can use the above syntax inside your frame:
\documentclass{beamer}
%\usetheme{CambridgeUS}
\usepackage[english]{babel}
\parskip=20pt
\begin{document}
\begin{frame}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\parskip=20pt
Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat.
\parskip=0pt
Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat.
Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat.
\end{frame}
\end{document}
The second \parskip=0pt sets all the following occurrencies of this length back to 0 pt (as I think 0 is the default here otherwise).
If you want to give space between two paragraphs,
use \newline as many times as the space you want. Using \newline once serves the same purpose as the double-backslash.